batch input to organize
Moderator: DosItHelp
Re: batch input to organize
Liviu, I tried your suggestion to see if it would work.
" but changing "move /-y *.%%x" to "move /-y %drive%\*.%%x" will move the files _from_ the root of the selected drive, instead"
but, I get this "The filename, directory name, or volume label syntax is incorrect.
" but changing "move /-y *.%%x" to "move /-y %drive%\*.%%x" will move the files _from_ the root of the selected drive, instead"
but, I get this "The filename, directory name, or volume label syntax is incorrect.
Re: batch input to organize
it was changed to what you said. Did I do it right?
if not exist %drive%\ORGANIZED\DOCUMENTS md %drive%\ORGANIZED\DOCUMENTS
for %%x in (doc txt docx pdf rtf vsd wpd wri) do move /-y %drive%\*.%%x\ORGANIZED\DOCUMENTS
if not exist %drive%\ORGANIZED\DOCUMENTS md %drive%\ORGANIZED\DOCUMENTS
for %%x in (doc txt docx pdf rtf vsd wpd wri) do move /-y %drive%\*.%%x\ORGANIZED\DOCUMENTS
Re: batch input to organize
The FOR LOOPS are looking for files in the current working directory.
You will need to change to the drive letter you want to process first.
You can just put the Drive Letter on a line by itself or use the PUSHD command.
You will need to change to the drive letter you want to process first.
You can just put the Drive Letter on a line by itself or use the PUSHD command.
Re: batch input to organize
Don´t get you Squashman, what should I change "for %%x in " to what?
The code is there, will be easy if you change it and highlight it.
Sorry!
The code is there, will be easy if you change it and highlight it.
Sorry!
Re: batch input to organize
Before your first IF not exist you can do this
or
If you use the pushd then put the POPD command after your last FOR command.
Code: Select all
%drive%
or
Code: Select all
pushd %drive%
If you use the pushd then put the POPD command after your last FOR command.
Re: batch input to organize
As an intellectual exercise it's good - but if you ran that on my machine and recursed through folders then I'd break your nose.
What I'm trying to say is that the purpose is fine if it is your machine, but to do that on someone else's machine (who may have things sorted in their own way) then it could be quite destructive.
The way I would approach this as an exercise is to use pushd to change the working directory to the root of the drive.
EG: If drive is set to "d:" without the quotes then use this:
Squashman has just posted this same - but I'll post this anyway.
What I'm trying to say is that the purpose is fine if it is your machine, but to do that on someone else's machine (who may have things sorted in their own way) then it could be quite destructive.
The way I would approach this as an exercise is to use pushd to change the working directory to the root of the drive.
EG: If drive is set to "d:" without the quotes then use this:
Code: Select all
pushd "%drive%\"
:: run your code here
popd
Squashman has just posted this same - but I'll post this anyway.
Re: batch input to organize
First off, the pushd/popd suggestion has my vote, too.
"move /-y *.%%x %drive%\ORGANIZED\DOCUMENTS"
before, and if you replaced ""move /-y *.%%x" with "move /-y %drive%\*.%%x", then you'd get
"move /-y %drive%\*.%%x %drive%\ORGANIZED\DOCUMENTS"
which was my suggestion. Note however that once you use pushd/popd, instead, you do no need this change.
You are right, of course. Suppose one had a saved .html page linking to a .jpg also saved in the same directory. After the move, the .html would no longer work, and the .jpg would be orphaned. On the other hand, users who routinely save everything to the root directory most likely don't have things "sorted in their own way"
Liviu
Just to clarify, that's wrong, and it's not what I said. You hadblackpete wrote:for %%x in (doc txt docx pdf rtf vsd wpd wri) do move /-y %drive%\*.%%x\ORGANIZED\DOCUMENTS
"move /-y *.%%x %drive%\ORGANIZED\DOCUMENTS"
before, and if you replaced ""move /-y *.%%x" with "move /-y %drive%\*.%%x", then you'd get
"move /-y %drive%\*.%%x %drive%\ORGANIZED\DOCUMENTS"
which was my suggestion. Note however that once you use pushd/popd, instead, you do no need this change.
foxidrive wrote:What I'm trying to say is that the purpose is fine if it is your machine, but to do that on someone else's machine (who may have things sorted in their own way)
You are right, of course. Suppose one had a saved .html page linking to a .jpg also saved in the same directory. After the move, the .html would no longer work, and the .jpg would be orphaned. On the other hand, users who routinely save everything to the root directory most likely don't have things "sorted in their own way"
Liviu
Re: batch input to organize
Liviu wrote:On the other hand, users who routinely save everything to the root directory most likely don't have things "sorted in their own way"
Liviu
But that makes it easier to find evrything!
Re: batch input to organize
Okay guys, I like the gathering of the forum´s members. sorry Liviu if I didn´t get your instructions right, and Liviu you are also right with the html example that you mention, but this batch is not for advance users that have their files sorted in their own way, this batch is for everyday people that don´t have the time to organize their files, this does not go thru folders, it just take all the loose files, on the desktop, or the root of D:, or a flashcard.
Back to the blackboard!
Back to the blackboard!
Re: batch input to organize
Last but not least!
I tried the pushd "%drive%\" before the code and popd at the end, did the job, but kept on showing two things that I don´t need.
One was the "A duplicate file name exist, or the file cannot be found.", and the other thing that shows now is the list of the files that were moved.
So I took off the " pushd "%drive%\" before the code and popd at the end", and added the "move 2>nul" to avoid the "A duplicate file name exist, or the file cannot be found.".
But still shows the list of files that were moved, where do they come from?
I tried the pushd "%drive%\" before the code and popd at the end, did the job, but kept on showing two things that I don´t need.
One was the "A duplicate file name exist, or the file cannot be found.", and the other thing that shows now is the list of the files that were moved.
So I took off the " pushd "%drive%\" before the code and popd at the end", and added the "move 2>nul" to avoid the "A duplicate file name exist, or the file cannot be found.".
But still shows the list of files that were moved, where do they come from?
Re: batch input to organize
sorry, I forgot to show you the code.
set drive=
set /p drive= which drive you want to organize first?
if "%drive%"=="1" (set "drive=C:"
)else if "%drive%"=="2" (set "drive=D:"
)else if "%drive%"=="3" (set "drive=E:"
)else if "%drive%"=="4" (set "drive=F:"
)else if "%drive%"=="5" (set "drive=G:"
)else if "%drive%"=="6" (set "drive=H:"
)else if "%drive%"=="7" (set "drive=I:"
)else if "%drive%"=="8" (goto :eof
) else goto :menu
if not exist %drive%\ORGANIZED\DOCUMENTS md %drive%\ORGANIZED\DOCUMENTS
for %%x in (doc txt docx pdf rtf vsd wpd wri) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\DOCUMENTS
if not exist %drive%\ORGANIZED\PHOTOS md %drive%\ORGANIZED\PHOTOS
for %%x in (bmp gif jpg jped png tiff psd psp wmf) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\PHOTOS
if not exist %drive%\ORGANIZED\MUSIC md %drive%\ORGANIZED\MUSIC
for %%x in (mp3 wav wma mid m4a au ape) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\MUSIC
if not exist %drive%\ORGANIZED\POWERPOINT md %drive%\ORGANIZED\POWERPOINT
for %%x in (ppt pptx) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\POWERPOINT
if not exist %drive%\ORGANIZED\EXCEL md %drive%\ORGANIZED\EXCEL
for %%x in (xls xlsx) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\EXCEL
if not exist %drive%\ORGANIZED\VIDEO md %drive%\ORGANIZED\VIDEO
for %%x in (wmv avi mov flv m4v rmvb mpeg) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\VIDEO
if not exist %drive%\ORGANIZED\INTERNET-FILES md %drive%\ORGANIZED\INTERNET-FILES
for %%x in (htm html) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\INTERNET-FILES
ECHO .....................................................................
ECHO REMEMBER, LOOK FOR FOLDER "ORGANIZED" IN THE DRIVE YOU SELECTED
ECHO .....................................................................
pause
set drive=
set /p drive= which drive you want to organize first?
if "%drive%"=="1" (set "drive=C:"
)else if "%drive%"=="2" (set "drive=D:"
)else if "%drive%"=="3" (set "drive=E:"
)else if "%drive%"=="4" (set "drive=F:"
)else if "%drive%"=="5" (set "drive=G:"
)else if "%drive%"=="6" (set "drive=H:"
)else if "%drive%"=="7" (set "drive=I:"
)else if "%drive%"=="8" (goto :eof
) else goto :menu
if not exist %drive%\ORGANIZED\DOCUMENTS md %drive%\ORGANIZED\DOCUMENTS
for %%x in (doc txt docx pdf rtf vsd wpd wri) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\DOCUMENTS
if not exist %drive%\ORGANIZED\PHOTOS md %drive%\ORGANIZED\PHOTOS
for %%x in (bmp gif jpg jped png tiff psd psp wmf) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\PHOTOS
if not exist %drive%\ORGANIZED\MUSIC md %drive%\ORGANIZED\MUSIC
for %%x in (mp3 wav wma mid m4a au ape) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\MUSIC
if not exist %drive%\ORGANIZED\POWERPOINT md %drive%\ORGANIZED\POWERPOINT
for %%x in (ppt pptx) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\POWERPOINT
if not exist %drive%\ORGANIZED\EXCEL md %drive%\ORGANIZED\EXCEL
for %%x in (xls xlsx) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\EXCEL
if not exist %drive%\ORGANIZED\VIDEO md %drive%\ORGANIZED\VIDEO
for %%x in (wmv avi mov flv m4v rmvb mpeg) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\VIDEO
if not exist %drive%\ORGANIZED\INTERNET-FILES md %drive%\ORGANIZED\INTERNET-FILES
for %%x in (htm html) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\INTERNET-FILES
ECHO .....................................................................
ECHO REMEMBER, LOOK FOR FOLDER "ORGANIZED" IN THE DRIVE YOU SELECTED
ECHO .....................................................................
pause
Re: batch input to organize
Do you have this at the top of your batch file?
@echo off
@echo off
Re: batch input to organize
blackpete wrote:Last but not least!
I tried the pushd "%drive%\" before the code and popd at the end, did the job, but kept on showing two things that I don´t need.
One was the "A duplicate file name exist, or the file cannot be found."
The pushd doesn't cause that. The problem can't be a duplicate filename if it is working from a single folder, so it must be a hidden or system file in the folder
, and the other thing that shows now is the list of the files that were moved.
So I took off the " pushd "%drive%\" before the code and popd at the end", and added the "move 2>nul" to avoid the "A duplicate file name exist, or the file cannot be found.".
But still shows the list of files that were moved, where do they come from?
use this
move source target >nul
Re: batch input to organize
'
Hi blackpete,
I tried to understand what you were after, this is the best I could come up with.
Ed
Hi blackpete,
I tried to understand what you were after, this is the best I could come up with.
Code: Select all
@echo off &prompt $G &setlocal enableDelayedExpansion
:init ()
:: (
call :menu %*
echo.Is this what you want ?
pause
:: )
exit /b 0
:menu ()
:: (
cls
echo.
set "?=C,D,E,F,G,H,I" &set "$=" &set /p "$= which drive you want to organize first[!?!]?"
::
if defined $ if /i "!?!" neq "!?:%$%=!" (
set "$drive=!$!:"
call :organize "()"
) else goto :menu "()"
:: )
exit /b 0
:organize ()
:: (
for /f "usebackq tokens=1 delims==" %%? in ( `2^>nul set #` ) do set "%%~?="
::
set "#DOCUMENTS=doc,txt,docx,pdf,rtf,vsd,wpd,wri"
set "#PHOTOS=bmp,gif,jpg,jped,png,tiff,psd,psp,wmf"
set "#MUSIC=mp3,wav,wma,mid,m4a,au,ape"
set "#POWERPOINT=ppt,pptx"
set "#EXCEL=xls,xlsx"
set "#VIDEO=wmv,avi,mov,flv,m4v,rmvb,mpeg"
set "#INTERNET-FILES=htm,html"
2>nul (
for /f "usebackq tokens=1-2 delims=#=" %%a in (
`set #`
) do echo.md "!$drive!\ORGANIZED\%%~a" &for %%? in (
%%~b
) do echo.move /-y "!$drive!\*.%%~?" "!$drive!\ORGANIZED\%%~a\"
)
:: )
exit /b 0
Ed
Re: batch input to organize
Hi Ed, thought the OP was one ">nul" away from having his wish granted, and now you come and ruin everything
Don't get me wrong, yours is nice and leaner code. However, given the context, I'm afraid it might raise more questions than answer.
Now that you opened the gates, may I also point that:
- "jped" under PHOTOS is a misspelling of "jpeg";
- "docx" under DOCUMENTS, "pptx" under POWERPOINT, "xlsx" under EXCEL, and "html" under INTERNET are redundant except in the rare case of an NTFS volume with NtfsDisable8dot3NameCreation=1 (otherwise for example *.doc will match .docx files, too, due to the short 8.3 name).
Liviu
Don't get me wrong, yours is nice and leaner code. However, given the context, I'm afraid it might raise more questions than answer.
Now that you opened the gates, may I also point that:
- "jped" under PHOTOS is a misspelling of "jpeg";
- "docx" under DOCUMENTS, "pptx" under POWERPOINT, "xlsx" under EXCEL, and "html" under INTERNET are redundant except in the rare case of an NTFS volume with NtfsDisable8dot3NameCreation=1 (otherwise for example *.doc will match .docx files, too, due to the short 8.3 name).
Liviu