General Question

XOIIO's avatar

Why isn't this batch script working?

Asked by XOIIO (18328points) October 21st, 2011

I’m making this script to automatically sort recovered files, but it gives parse errror each time. I need it to copy all files from subdirectories, and not ask to overwrite. Please help.

@echo off
title File Organizer
color 0a
echo.
echo [][][][][][][][][][][][][][][][]
echo [] /\ []
echo [] [] []
echo [] [][] []
echo [] [] [] []
echo [] [] [] []
echo [] [] [] []
echo [] /\][][][][/\ []
echo []// \\[]
echo [] []
echo [] []
echo [] []
echo [] []
echo [] []
echo [] []
echo [][]
echo []
ping localhost -n 2 >nul
:FilePath
cls
echo Enter The File Path To Be Sorted:
echo.
set /p FilePath=
echo.
echo Is %FilePath% Correct? (Y/N)

set /p note=
if ’%note%’==‘Y’ GOTO Sort
if ’%note%’==‘y’ GOTO Sort
if ’%note%’==‘N’ GOTO FilePath
if ’%note%’==‘n’ GOTO FilePath

:Sort
echo Now Sorting Files. Folders Will Be Created In Current Directory.
echo.
echo Creating Directories…
MKDIR FileSort
MKDIR FileSort\Compressed
MKDIR FileSort\Music
MKDIR FileSort\Video
MKDIR FileSort\Pictures
MKDIR FileSort\Documents

echo.
echo Complete
echo.
echo Now Beginning Sorting…
ping localhost -n 2 >nul
echo.

echo Sorting Music
echo.
XCOPY /S /Y “%FilePath%\*.mp3” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.wav” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.caf” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.m4a” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.m4r” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.aac” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.aiff” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.au” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.3gp” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.flac” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.m4p” “FileSort\Music\”
XCOPY /S /Y “%FilePath%\*.mma” “FileSort\Music\”
echo.

echo Sorting Video
echo.
XCOPY /S /Y “%FilePath%\*.aaf” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.3gp” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.avi” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.flv” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.m4v” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.mkv” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.mov” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.mpeg” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.mpg” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.mpe” “FileSort\Video\”
XCOPY /S /Y “%FilePath%\*.wmv” “FileSort\Video\”
echo.

echo Sorting Pictures
echo.
XCOPY /S /Y “%FilePath%\*.jpg” “FileSort\Pictures\”
XCOPY /S /Y “%FilePath%\*.jpeg” “FileSort\Pictures\”
XCOPY /S /Y “%FilePath%\*.png” “FileSort\Pictures\”
XCOPY /S /Y “%FilePath%\*.bmp” “FileSort\Pictures\”
XCOPY /S /Y “%FilePath%\*.gif” “FileSort\Pictures\”
XCOPY /S /Y “%FilePath%\*.tiff” “FileSort\Pictures\”
echo.

echo Sorting Compressed Files
echo.
XCOPY /S /Y “%FilePath%\*.zip” “FileSort\Compressed\”
XCOPY /S /Y “%FilePath%\*.rar” “FileSort\Compressed\”
XCOPY /S /Y “%FilePath%\*.7zip” “FileSort\Compressed\”
echo.

echo Sorting Documents
echo.
XCOPY /S /Y “%FilePath%\*.doc” “FileSort\Documents\”
XCOPY /S /Y “%FilePath%\*.docx” “FileSort\Documents\”
XCOPY /S /Y “%FilePath%\*.ppt” “FileSort\Documents\”
XCOPY /S /Y “%FilePath%\*.pptx” “FileSort\Documents\”
XCOPY /S /Y “%FilePath%\*.xls” “FileSort\Documents\”
XCOPY /S /Y “%FilePath%\*.xlsx” “FileSort\Documents\”
XCOPY /S /Y “%FilePath%\*.txt” “FileSort\Documents\”

Pause>nul

Observing members: 0 Composing members: 0

12 Answers

dabbler's avatar

What’s the shell? Is that windows cmd?
Any details to the parse error ?
Does “not ask to overwrite” mean don’t overwrite, or you don’t want it to stop and ask you the question?

XOIIO's avatar

This is a batch script, so it’s cmd. I have the right flags to supress prompting, I just don’t get why is gives a parse error

dabbler's avatar

no details on that parsing error ? Does it identify a line or chunk of bad code or tell you a type of error ? (i.e. besides “parse error” )

XOIIO's avatar

Just parse error. Try it yourself

dabbler's avatar

I’m not on a windows box right now… no “cmd” interpreter on this box
My advice at this time is to cut/paste/run a chunk of it at a time until you run into the problem.

XOIIO's avatar

Well everything runs fine, but for some reason Xcopy dfoesnt work. Robocopy wont do this properly either, and regular copy wont copy subdirectories as far as I know.

XOIIO's avatar

This version works for some reason

@echo off
title File Organizer
color 0a
echo.
echo [][][][][][][][][][][][][][][][]
echo [] /\ []
echo [] [] []
echo [] [][] []
echo [] [] [] []
echo [] [] [] []
echo [] [] [] []
echo [] /\][][][][/\ []
echo []// \\[]
echo [] []
echo [] []
echo [] []
echo [] []
echo [] []
echo [] []
echo [][]
echo []
ping localhost -n 2 >nul
:FilePath
cls
echo Enter The File Path To Be Sorted:
echo.
set /p FilePath=
echo.
echo Is %FilePath% Correct? (Y/N)

set /p note=
if ’%note%’==‘Y’ GOTO Sort
if ’%note%’==‘y’ GOTO Sort
if ’%note%’==‘N’ GOTO FilePath
if ’%note%’==‘n’ GOTO FilePath

:Sort
echo Now Sorting Files. Folders Will Be Created In Current Directory.
echo.
echo Creating Directories…
MKDIR FileSort
MKDIR FileSort\Compressed
MKDIR FileSort\Music
MKDIR FileSort\Video
MKDIR FileSort\Pictures
MKDIR FileSort\Documents

echo.
echo Complete
echo.
echo Now Beginning Sorting…
ping localhost -n 2 >nul
echo.

echo Sorting Music
echo.
XCOPY /S /E /H /Y ”%FilePath%\*.mp3” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.wav” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.caf” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.m4a” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.m4r” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.aac” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.aiff” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.au” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.3gp” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.flac” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.m4p” “FileSort\Music\”
XCOPY /S /E /H /Y ”%FilePath%\*.mma” “FileSort\Music\”
echo.

echo Sorting Video
echo.
XCOPY /S /E /H /Y ”%FilePath%\*.aaf” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.3gp” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.avi” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.flv” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.m4v” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.mkv” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.mov” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.mpeg” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.mpg” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.mpe” “FileSort\Video\”
XCOPY /S /E /H /Y ”%FilePath%\*.wmv” “FileSort\Video\”
echo.

echo Sorting Pictures
echo.
XCOPY /S /E /H /Y ”%FilePath%\*.jpg” “FileSort\Pictures\”
XCOPY /S /E /H /Y ”%FilePath%\*.jpeg” “FileSort\Pictures\”
XCOPY /S /E /H /Y ”%FilePath%\*.png” “FileSort\Pictures\”
XCOPY /S /E /H /Y ”%FilePath%\*.bmp” “FileSort\Pictures\”
XCOPY /S /E /H /Y ”%FilePath%\*.gif” “FileSort\Pictures\”
XCOPY /S /E /H /Y ”%FilePath%\*.tiff” “FileSort\Pictures\”
echo.

echo Sorting Compressed Files
echo.
XCOPY /S /E /H /Y ”%FilePath%\*.zip” “FileSort\Compressed\”
XCOPY /S /E /H /Y ”%FilePath%\*.rar” “FileSort\Compressed\”
XCOPY /S /E /H /Y ”%FilePath%\*.7zip” “FileSort\Compressed\”
echo.

echo Sorting Documents
echo.
XCOPY /S /E /H /Y ”%FilePath%\*.doc” “FileSort\Documents\”
XCOPY /S /E /H /Y ”%FilePath%\*.docx” “FileSort\Documents\”
XCOPY /S /E /H /Y ”%FilePath%\*.ppt” “FileSort\Documents\”
XCOPY /S /E /H /Y ”%FilePath%\*.pptx” “FileSort\Documents\”
XCOPY /S /E /H /Y ”%FilePath%\*.xls” “FileSort\Documents\”
XCOPY /S /E /H /Y ”%FilePath%\*.xlsx” “FileSort\Documents\”
XCOPY /S /E /H /Y ”%FilePath%\*.txt” “FileSort\Documents\”

Pause>nul

dabbler's avatar

Ah, the /E makes sense. Good show.

XOIIO's avatar

Just wondering, is there a wayto dump the contents of the entire DOS console to a text file after its done? I know you use >file.txt, but not sure how to output everything at once.

dabbler's avatar

Heck, I’d try a copy/paste once it’s already happened.
There is probably a terminal app out there that will dump everything in the scroll buffer with a menu option but I don’t know which offhand.

XOIIO's avatar

Dang, I do’t want t have two copies of everything putting the output into a text file XD

dabbler's avatar

I’m hardly as used to cmd as I am to other shells (sh/csh/ksh in particular) but redirects such as >file.txt are good for logging, and you are smart to have lots of ‘echo’ comments for the output.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther