Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Help creating batch archive function?


  • Please log in to reply
2 replies to this topic

#1 schwack

schwack

  • Members
  • 6 posts
  • OFFLINE
  •  
  • Local time:10:59 AM

Posted 17 June 2011 - 08:50 AM

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

BC AdBot (Login to Remove)

 


#2 whoabuddy

whoabuddy

    Bleepin' Verbose


  • Malware Response Instructor
  • 2,053 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Cottonwood, AZ
  • Local time:07:59 AM

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:

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


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:

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


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.
Vi Veri Universum Vivus Vici (VVVVV)
Excellent Security Advice
Proud member of UNITE

#3 schwack

schwack
  • Topic Starter

  • Members
  • 6 posts
  • OFFLINE
  •  
  • Local time:10:59 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users