moving files
Moderator: DosItHelp
-
- Posts: 17
- Joined: 12 Feb 2017 05:11
moving files
hi
I have a folder containing a mix of files around 100000 in number
they are mainly .pdf .mp4 .doc .docx .mov .xls .xlsx
can someone help me sort these files to separate folders (ie pdf mp4 doc docx.... and so on)
thanks
and regards
joe
I have a folder containing a mix of files around 100000 in number
they are mainly .pdf .mp4 .doc .docx .mov .xls .xlsx
can someone help me sort these files to separate folders (ie pdf mp4 doc docx.... and so on)
thanks
and regards
joe
Re: moving files
try this:
Code: Select all
@echo off
setlocal enabledelayedexpansion
cd .
set "list=pdf mp4 doc docx mov xls xlsx"
for %%1 in (%list%) do (mkdir %%1)
for /f "tokens=*" %%a in ('dir /b /o:n /a-d *.') do (
set a=%%a
for %%b in (%list%) do (
if "!a:~-4!" == "%%b" (
move !a! %%b
) else if "!a:~-3!" == "%%b" (
move !a! %%b
)
)
)
-
- Posts: 17
- Joined: 12 Feb 2017 05:11
Re: moving files
hi
the script when executed creates the directory but fails to move the files..
thanks
the script when executed creates the directory but fails to move the files..
thanks
Re: moving files
Code: Select all
@echo off
setlocal enabledelayedexpansion
cd .
set "list=pdf mp4 doc docx mov xls xlsx"
for %%1 in (%list%) do (mkdir %%1)
for /f "tokens=*" %%a in ('dir /b /o:n /a-d *.') do (
set a=%%a
for %%b in (%list%) do (
if "!a:~-4!" == "%%b" (
robocopy !a! %%b /MOV
) else if "!a:~-3!" == "%%b" (
robocopy !a! %%b /MOV
)
)
)
Re: moving files
If the file names have spaces in the names then you need quotes around all the variables. Best practice is too always use quotes.
Re: moving files
Code: Select all
dir /b /o:n /a-d *.
Re: moving files
sorry, i forgot to change that part when i copied the code from my other post
Code: Select all
@echo off
setlocal enabledelayedexpansion
cd .
set "list=pdf mp4 doc docx mov xls xlsx"
for %%1 in (%list%) do (mkdir %%1)
for /f "tokens=*" %%a in ('dir /b /o:n') do (
set a=%%a
for %%b in (%list%) do (
if "!a:~-4!" == "%%b" (
move !a! %%b
) else if "!a:~-3!" == "%%b" (
move !a! %%b
) else (
REM
)
)
)
-
- Posts: 17
- Joined: 12 Feb 2017 05:11
Re: moving files
yes that did the job
thankyou very much
thankyou very much
Re: moving files
so put quotes around it, right?
Code: Select all
move "!a!" %%b
Re: moving files
As I said earlier it is best practice to always use quotes. So I would put quotes around both. Granted you know that the directory name does not have spaces but if someone takes your code and starts modifying it again to use with directory names that have spaces then your code will fail again.
-
- Posts: 17
- Joined: 12 Feb 2017 05:11
Re: moving files
yes squashman was right it moves files without spaces but leaves behind all those files with spaces in their names
even after adding quotes..
even after adding quotes..
Re: moving files
add quotes to both variables in both if statements?
Code: Select all
if "!a:~-4!" == "%%b" (
move "!a!" "%%b"
) else if "!a:~-3!" == "%%b" (
move "!a!" "%%b"
) else (
REM
)
Re: moving files
Code: Select all
@echo off &setlocal DisableDelayedExpansion
for %%i in (*.*) do if "%%~i" neq "%~nx0" for /f "tokens=* delims=." %%j in ("%%~xi") do (
if not exist "%%j\" md "%%j"
move "%%~i" "%%j\"
)
-
- Posts: 17
- Joined: 12 Feb 2017 05:11
Re: moving files
hi
I was just wondering what happened to steffen!!
I was getting anxious as time passed by
wow that was the ultimate solution
steffen you really ROCK MAN
THANKYOU VERY MUUUUUCCCCCCHHHHHHH
I was just wondering what happened to steffen!!
I was getting anxious as time passed by
wow that was the ultimate solution
steffen you really ROCK MAN
THANKYOU VERY MUUUUUCCCCCCHHHHHHH