batch input to organize
Moderator: DosItHelp
batch input to organize
I am kind of frustrated, and my neck is sore reading about batch files, and cannot find a solution, so I really hope you can help me.
I am trying to do a batch file to organize documents, photos,etc. that part is already working, but I want the batch file to ask for input about which drive you want to organize first. It sound simple, but l haven´t being able to do it.
I am working with windows7 if you need that info.
thanks
I will appreciate any help
I am trying to do a batch file to organize documents, photos,etc. that part is already working, but I want the batch file to ask for input about which drive you want to organize first. It sound simple, but l haven´t being able to do it.
I am working with windows7 if you need that info.
thanks
I will appreciate any help
Last edited by blackpete on 01 Aug 2012 11:57, edited 1 time in total.
Re: batch input
'
Code: Select all
@echo off
set /?
pause
set /p "$=which drive you want to organize first:"
set $
pause
Re: batch input
with that I got almost a full page of how to use the set command, isn´t there something simpler, like
set p/ %drive% and it will ask for what drive?
Sorry!
set p/ %drive% and it will ask for what drive?
Sorry!
Re: batch input
look at this and tell me why the set doesn´t work!
ECHO OFF
CLS
:MENU
ECHO.
ECHO 1 - C:
ECHO 2 - D:
ECHO 3 - E:
ECHO 4 - F:
ECHO 5 - G:
ECHO 6 - H:
ECHO 7 - I:
ECHO 8 - EXIT
ECHO.
set /p drive= which drive you want to organize first?
if %drive%==1 goto C:
MD ORGANIZADO\DOCUMENTOS
if not exist ORGANIZADO\DOCUMENTOS\nul md\DOCUMENTOS
MD ORGANIZADO\FOTOS
if not exist ORGANIZADO\FOTOS\nul md\FOTOS
MD ORGANIZADO\MUSICA
if not exist ORGANIZADO\MUSICA\nul md\MUSICA
MD ORGANIZADO\POWERPOINT
if not exist ORGANIZADO\POWERPOINT\nul md\POWERPOINT
MD ORGANIZADO\EXCEL
if not exist ORGANIZADO\EXCEL\nul md\EXCEL
MD ORGANIZADO\VIDEO
if not exist ORGANIZADO\VIDEO\nul md\VIDEO
MD ORGANIZADO\ARCHIVOS-INTERNET
if not exist ORGANIZADO\ARCHIVOS-INTERNET\nul md\ARCHIVOS-INTERNET
move /-y *.doc C: ORGANIZADO\DOCUMENTOS
move /-y *.txt C: ORGANIZADO\DOCUMENTOS
move /-y *.docx C: ORGANIZADO\DOCUMENTOS
move /-y *.pdf C: ORGANIZADO\DOCUMENTOS
move /-y *.rtf C: ORGANIZADO\DOCUMENTOS
move /-y *.bmp C: ORGANIZADO\FOTOS
move /-y *.gif C: ORGANIZADO\FOTOS
move /-y *.jpg C: ORGANIZADO\FOTOS
move /-y *.jped C: ORGANIZADO\FOTOS
move /-y *.mp3 C: ORGANIZADO\MUSICA
move /-y *.wav C: ORGANIZADO\MUSICA
move /-y *.ppt C: ORGANIZADO\POWERPOINT
move /-y *.xls C: ORGANIZADO\EXCEL
move /-y *.wmv C: ORGANIZADO\VIDEO
move /-y *.avi C: ORGANIZADO\VIDEO
move /-y *.htm C: ORGANIZADO\ARCHIVOS-INTERNET
ECHO OFF
CLS
:MENU
ECHO.
ECHO 1 - C:
ECHO 2 - D:
ECHO 3 - E:
ECHO 4 - F:
ECHO 5 - G:
ECHO 6 - H:
ECHO 7 - I:
ECHO 8 - EXIT
ECHO.
set /p drive= which drive you want to organize first?
if %drive%==1 goto C:
MD ORGANIZADO\DOCUMENTOS
if not exist ORGANIZADO\DOCUMENTOS\nul md\DOCUMENTOS
MD ORGANIZADO\FOTOS
if not exist ORGANIZADO\FOTOS\nul md\FOTOS
MD ORGANIZADO\MUSICA
if not exist ORGANIZADO\MUSICA\nul md\MUSICA
MD ORGANIZADO\POWERPOINT
if not exist ORGANIZADO\POWERPOINT\nul md\POWERPOINT
MD ORGANIZADO\EXCEL
if not exist ORGANIZADO\EXCEL\nul md\EXCEL
MD ORGANIZADO\VIDEO
if not exist ORGANIZADO\VIDEO\nul md\VIDEO
MD ORGANIZADO\ARCHIVOS-INTERNET
if not exist ORGANIZADO\ARCHIVOS-INTERNET\nul md\ARCHIVOS-INTERNET
move /-y *.doc C: ORGANIZADO\DOCUMENTOS
move /-y *.txt C: ORGANIZADO\DOCUMENTOS
move /-y *.docx C: ORGANIZADO\DOCUMENTOS
move /-y *.pdf C: ORGANIZADO\DOCUMENTOS
move /-y *.rtf C: ORGANIZADO\DOCUMENTOS
move /-y *.bmp C: ORGANIZADO\FOTOS
move /-y *.gif C: ORGANIZADO\FOTOS
move /-y *.jpg C: ORGANIZADO\FOTOS
move /-y *.jped C: ORGANIZADO\FOTOS
move /-y *.mp3 C: ORGANIZADO\MUSICA
move /-y *.wav C: ORGANIZADO\MUSICA
move /-y *.ppt C: ORGANIZADO\POWERPOINT
move /-y *.xls C: ORGANIZADO\EXCEL
move /-y *.wmv C: ORGANIZADO\VIDEO
move /-y *.avi C: ORGANIZADO\VIDEO
move /-y *.htm C: ORGANIZADO\ARCHIVOS-INTERNET
Re: batch input
Did you read it? Pretty much answers your next question.blackpete wrote:with that I got almost a full page of how to use the set command
What makes you think "set" doesn't work? It does, but then you have an illegal "goto C:".blackpete wrote:look at this and tell me why the set doesn´t work!
Not entirely clear on what your backup scheme is, but maybe this could work as a starting point.
Code: Select all
@echo off
setlocal
:MENU
CLS
ECHO.
ECHO 1 - C:
ECHO 2 - D:
ECHO 8 - EXIT
ECHO.
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%"=="8" (goto :eof
) else goto :menu
if not exist %drive%\ORGANIZADO\DOCUMENTOS md %drive%\ORGANIZADO\DOCUMENTOS
for %%x in (doc txt docx pdf rtf) do move /-y *.%%x %drive%\ORGANIZADO\DOCUMENTOS
Liviu
Re: batch input
Look and sound good, I am going to read the set command instructions, and then I will try your suggestion.
Thanks liviu, I´ll be back!
Thanks liviu, I´ll be back!
Re: batch input
Hey Liviu, so far so good, it did ask for a drive letter and moved the files to a new folder, but also showed some error:
"A duplicate file name exist, or the file cannot be found."
The scheme of this batch file is to be able to organize all the scattered files of different types into separate folders, being in the desktop, pendrive or a partition.
Okey, thanks, any feedback is welcome
"A duplicate file name exist, or the file cannot be found."
The scheme of this batch file is to be able to organize all the scattered files of different types into separate folders, being in the desktop, pendrive or a partition.
Okey, thanks, any feedback is welcome
Re: batch input
The "/-y" switch in "move /-y" would prompt to overwrite existing files. So it's probably the other case "file cannot be found" - you'll get the warning if you attempt to move *.doc but no .doc files exist in the current directory. Either "move 2>nul" to hide the warning, or precheck.blackpete wrote:showed some error: "A duplicate file name exist, or the file cannot be found."
Code: Select all
for %%x in (doc txt docx pdf rtf) do (
if exist *.%%x move /-y *.%%x %drive%\ORGANIZADO\DOCUMENTOS
)
Liviu
Re: batch input
That is great Liviu!
I will work on the rest of the batch with your suggestions. I really enjoy this forum, and to find somebody willing to help with down to earth explanation.
Keep up the good work!
I will work on the rest of the batch with your suggestions. I really enjoy this forum, and to find somebody willing to help with down to earth explanation.
Keep up the good work!
Re: batch input
one last thing
What will stop a file being overwritten because it have the same name, but in different folders? you know, with the move command taking *.doc per example, I can have a test.doc done yesterday and a test.doc done today, right? the last one could be the update of the other one.
Mmmmmmmmmmm!
What will stop a file being overwritten because it have the same name, but in different folders? you know, with the move command taking *.doc per example, I can have a test.doc done yesterday and a test.doc done today, right? the last one could be the update of the other one.
Mmmmmmmmmmm!
Re: batch input
If you are using someone else's system then you can't assume that two files with the same name, are on the same topic.
This is meant for use on another system, isn't it?
Your code above only sorts a single folder so there should not be any filename clashes - can you post your latest version?
Anyway, one method of getting around filename clashes is to add a random number to the file that clashes. Test to see if the new name exists and loop to pick a new random number if it does.
This is meant for use on another system, isn't it?
Your code above only sorts a single folder so there should not be any filename clashes - can you post your latest version?
Anyway, one method of getting around filename clashes is to add a random number to the file that clashes. Test to see if the new name exists and loop to pick a new random number if it does.
Code: Select all
set file=test.doc
:rand
for %%a in ("%file%") do set "newfilename=%%~na-%random%-%%~xa"
if exist "c:\destination\%newfilename%" goto :rand
echo "c:\destination\%newfilename%"
Re: batch input
Hi foxidrive, I started this when I was repairing people´s computers, and seeing how disorganized was their desktop files or for that matter the files kept in a different partition, or flashcard.
So my worry is that, I don´t want the batch to overwrite a file that has the same name, and it is in two or more locations.
It is simple, but at the same time, can be useful,right?
On your code: I don´t know what should go as test.doc or do I replace newfilename with something, and what goes on destination.
See, I did a DOS basic programming back in 1985, so please when you suggest a code, can you give me an easier explanation.
I will post the finish version,okay?
So my worry is that, I don´t want the batch to overwrite a file that has the same name, and it is in two or more locations.
It is simple, but at the same time, can be useful,right?
On your code: I don´t know what should go as test.doc or do I replace newfilename with something, and what goes on destination.
See, I did a DOS basic programming back in 1985, so please when you suggest a code, can you give me an easier explanation.
I will post the finish version,okay?
Re: batch input
Okey, I did all the changes.
The batch file as it is, it work on C: and does the job, but if I choose number 2 for drive D: it will make the folder "ORGANIZED" with all the sub folders, but does not move the files located on drive D:
I wonder why? Here is the file:
____________________________________________________________________________________________
@echo off
cls
:MENU
ECHO.
ECHO .....................................................................
ECHO THIS PROGRAM WILL ORGANIZE YOUR SCATTERED FILES INTO SEPARATE FOLDERS
ECHO -------WHEN IT IS DONE, LOOK FOR A FOLDER CALLED "ORGANIZED"---------
ECHO .....................................................................
ECHO.
ECHO 1 - C:
ECHO 2 - D:
ECHO 3 - E:
ECHO 4 - F:
ECHO 5 - G:
ECHO 6 - H:
ECHO 7 - I:
ECHO 8 - EXIT
ECHO.
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 /-y *.%%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 /-y *.%%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 /-y *.%%x %drive%\ORGANIZED\MUSIC
if not exist %drive%\ORGANIZED\POWERPOINT md %drive%\ORGANIZED\POWERPOINT
for %%x in (ppt pptx) do move /-y *.%%x %drive%\ORGANIZed\POWERPOINT
if not exist %drive%\ORGANIZED\EXCEL md %drive%\ORGANIZED\EXCEL
for %%x in (xls xlsx) do move /-y *.%%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 /-y *.%%x %drive%\ORGANIZED\VIDEO
if not exist %drive%\ORGANIZED\INTERNET-FILES md %drive%\ORGANIZED\INTERNET-FILES
for %%x in (htm html) do move /-y *.%%x %drive%\ORGANIZED\INTERNET-FILES
pause
ECHO .....................................................................
ECHO -----THAT IS ALL-------REMEMBER, LOOK FOR FOLDER "ORGANIZED"--------
ECHO .....................................................................
pause
The batch file as it is, it work on C: and does the job, but if I choose number 2 for drive D: it will make the folder "ORGANIZED" with all the sub folders, but does not move the files located on drive D:
I wonder why? Here is the file:
____________________________________________________________________________________________
@echo off
cls
:MENU
ECHO.
ECHO .....................................................................
ECHO THIS PROGRAM WILL ORGANIZE YOUR SCATTERED FILES INTO SEPARATE FOLDERS
ECHO -------WHEN IT IS DONE, LOOK FOR A FOLDER CALLED "ORGANIZED"---------
ECHO .....................................................................
ECHO.
ECHO 1 - C:
ECHO 2 - D:
ECHO 3 - E:
ECHO 4 - F:
ECHO 5 - G:
ECHO 6 - H:
ECHO 7 - I:
ECHO 8 - EXIT
ECHO.
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 /-y *.%%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 /-y *.%%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 /-y *.%%x %drive%\ORGANIZED\MUSIC
if not exist %drive%\ORGANIZED\POWERPOINT md %drive%\ORGANIZED\POWERPOINT
for %%x in (ppt pptx) do move /-y *.%%x %drive%\ORGANIZed\POWERPOINT
if not exist %drive%\ORGANIZED\EXCEL md %drive%\ORGANIZED\EXCEL
for %%x in (xls xlsx) do move /-y *.%%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 /-y *.%%x %drive%\ORGANIZED\VIDEO
if not exist %drive%\ORGANIZED\INTERNET-FILES md %drive%\ORGANIZED\INTERNET-FILES
for %%x in (htm html) do move /-y *.%%x %drive%\ORGANIZED\INTERNET-FILES
pause
ECHO .....................................................................
ECHO -----THAT IS ALL-------REMEMBER, LOOK FOR FOLDER "ORGANIZED"--------
ECHO .....................................................................
pause
Re: batch input
blackpete wrote:if I choose number 2 for drive D: it will make the folder "ORGANIZED" with all the sub folders, but does not move the files located on drive D:
Your code moves files from the current directory _to_ the drive you selected (in the respective folders).
Not sure that's what you want, but changing "move /-y *.%%x" to "move /-y %drive%\*.%%x" will move the files _from_ the root of the selected drive, instead.
Liviu
Re: batch input to organize
Yes Liviu, if I choose 1, I want to move all the different files in the root C: to the folder "organized" located in C:, and if I chosse 2, I want to move all the different files in the root D: to the folder "organize" located in the D: drive.
I don´t want to merge all the "organized" folders, not yet. See, probably then I would run into overwritting files with the same name.
Do you understand?
I don´t want to merge all the "organized" folders, not yet. See, probably then I would run into overwritting files with the same name.
Do you understand?