Question : Update - Creating a script that can move files to an existing directory based on filename


QCubed,

Thanks again....

I only need a DOS window indicating that the folder doesn't exist.  I don't need it to automatically create the folder as this has already been created by another program.

Mike



----------------------------------------------------------------------------
I need a script that can pickup files from a dump folder (i.e, J:\ScanFiles\Fax dump) and move them to different folders (which already exist), based on the ID portion of the filename.

For example, a file in J:\ScanFiles\Fax dump would be named "1056_7_22_10.pdf"  "1056" is the ID; note that this number could potentially be 6 figures or perhaps greater.  So there could also be a "1056_7_23_10.pdf" etc. in Fax dump.  These files should be moved to J:\ScanFiles\1056  This directory doesn't need to be created as it already exists.

So, as another example, a file in J:\ScanFiles\Fax dump named "51608_7_23_10.pdf" should be moved to J:\ScanFiles\51608   Again the destination directory already exists, the file just needs to be moved.

Thanks so much for your help!

Mike

Answer : Update - Creating a script that can move files to an existing directory based on filename

Hey, sorry I have been quit busy.  I ended up realizing we could do this all in one line and pop up a message box for you about the bad directory.

The attached code will check if the directory does not exist, and if it doesn't exist it will pop-up a message box warning you that the directory does not exist.

The code will continue to function and move on to the next file even if you don't click the message box. so you don't have to worry about this causing the script to stop functioning.
1:
2:
ECHO OFF
FOR /F "Tokens=1,* Delims=_" %%F IN ('DIR /A:-D "J:\ScanFiles\Fax dump\*_*.pdf" /B ') DO IF NOT EXIST "J:\ScanFiles\%%F\" ( MSG %Username% "The MovePDF Script Encountered an Error Moving a File to a Directory:                    The Directory Does Not Exist:  J:\ScanFiles\%%F\ " ) ELSE (MOVE /Y "J:\ScanFiles\Fax dump\%%F_%%G" "J:\ScanFiles\%%F\%%F_%%G")
Random Solutions  
 
programming4us programming4us