Hello,
I have a batch file that should be creating a dated folder within an archive folder, then moving the contents of a capture directory for that day to the corresponding folder.
The batch file looks like this:
FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET mydate=%%J%%K%%L
2
MOVE X:\*.* x:\OLD\%mydate%\ 1>>D:\Archive\Archivefail.LOG 2>&1
Here's a couple of the errors I see when trying to perform this task: (you'll notice some fashion of MKDIR \%mydate%\ is missing, that's because it didn't work properly)
"The system cannot find the drive specified." - this one I think I can fix with a simple NET USE X:\\SERVER\PATH command.
"The filename, directory name, or volume label syntax is incorrect." - this one has me puzzled. I should mention I am manually making dated folders within the \OLD\ directory until I can automate this better.
The other issue I have is that sometimes a file is in use, preventing the move of the rest of the files. I know this is a long shot, but is there any way in DOS if a file is in use to move on and archive the rest? What I'm really looking for is a fresh start to taking all the files written in X:\\SERVER\PATH and moving those files to X:\\SERVER\YYYYMMDD
Any insight on this script would be tremendously appreciated.
Regards,
schwack
Page 1 of 1
Help creating batch archive function? .bat file, automating file move and archival
#2
Posted 21 June 2011 - 04:24 PM
I don't believe there is an easy way to deal with in-use files in DOS, however I was able to get your code working with some slight modifications below:
I removed the "2" (not sure where it came from), and added a MD (or MKDIR) command with the correct syntax. Once I had that updated I was able to move the contents of test1 to a dated Archive folder without an issue. Without the MD command I received the error "Cannot move multiple files to a single file." in the log. If the X: drive still needs to be setup before the copy, you had the right NET USE command, but I would include it like this:
Hopefully that helps answer some of your questions!
Quote
FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET mydate=%%J%%K%%L
MD C:\Archive\%mydate%\
MOVE C:\test1\*.* C:\Archive\%mydate%\ 1>>C:\Archivefail.LOG 2>&1
MD C:\Archive\%mydate%\
MOVE C:\test1\*.* C:\Archive\%mydate%\ 1>>C:\Archivefail.LOG 2>&1
I removed the "2" (not sure where it came from), and added a MD (or MKDIR) command with the correct syntax. Once I had that updated I was able to move the contents of test1 to a dated Archive folder without an issue. Without the MD command I received the error "Cannot move multiple files to a single file." in the log. If the X: drive still needs to be setup before the copy, you had the right NET USE command, but I would include it like this:
Quote
FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET mydate=%%J%%K%%L
NET USE X: /DELETE
NET USE X: \\SERVER\SHARE /USER:DOMAIN\USERNAME PASSWORD
MD X:\Archive\%mydate%\
MOVE X:\test1\*.* X:\Archive\%mydate%\ 1>>X:\Archivefail.LOG 2>&1
NET USE X: /DELETE
NET USE X: \\SERVER\SHARE /USER:DOMAIN\USERNAME PASSWORD
MD X:\Archive\%mydate%\
MOVE X:\test1\*.* X:\Archive\%mydate%\ 1>>X:\Archivefail.LOG 2>&1
Hopefully that helps answer some of your questions!
Meditate. Elevate. Appreciate.
"Life is a journey, love is the destination, happiness is the path!"
If I am helping you and have not responded within 48 hours, please send me a PM.
"Life is a journey, love is the destination, happiness is the path!"
If I am helping you and have not responded within 48 hours, please send me a PM.
#3
Posted 21 June 2011 - 05:29 PM
Thanks so much for the help! I'll give it a try with tonight's archive and see how it goes!
Share this topic:
Page 1 of 1

Help

Back to top









