Solved

DOS Batch Script

Posted on 2009-05-07
3
594 Views
Last Modified: 2012-05-06
Im trying create BAT file that will backup a drive as follows

Create Directory F:\Todays Date
Copy all files from C:\ISD to F:\Todays Date

I searched for code online but nothing is straight foward.  I know that i need the xcopy command and the Mkdir command, but i am having hard time creating Folder with todays date.
Once i get the above backup.bat file, i am going to put in the daily Task schdule to run.

Thank you
0
Comment
Question by:IsdNG
  • 2
3 Comments
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24332736
Try this.  If you run xcopy /? you can see all the params you can apply, I included only /E which copies all subfiles and folders including empty ones.

@echo off
set _folder=%date:~10,4%-%date:~4,2%-%date:~7,2%
if not exist "f:\_%folder%" mkdir "f:\%_folder%"
xcopy "c:\isd" "f:\_%folder%" /e

Open in new window

0
 
LVL 13

Accepted Solution

by:
usachrisk1983 earned 250 total points
ID: 24332744
Sorry, screwed up the variables :)   Resolved below.

@echo off
set _folder=%date:~10,4%-%date:~4,2%-%date:~7,2%
if not exist "f:\%_folder%" mkdir "f:\%_folder%"
xcopy "c:\isd" "f:\%_folder%" /e

Open in new window

0
 

Author Closing Comment

by:IsdNG
ID: 31579295
Your Awesome, thank you very much!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question