Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there
I use XCOPY to backup all files from my computer to an external hard disk. Currently, it is always to the same folder (X:\backup) with only newer files being updated.I would like to improve my backups by creating a new backup folder for each date I run the backup batch file - e.g. X:\10-07-08-backup or something similar, and then dump a complete copy of everything I backup using xcopy (c:\documents and settings) into the folder with that date.
How? Thanks!

Something like this?
@echo off
set month=%date:~4,2%
set day=%date:~7,2%
set year=%date:~10,4%
set dir="C:\Documents and Settings\SomeUser\stuff"
echo %year%
xcopy %dir%\*.* %month%-%day%-%year%-backup\ /q

@echo off
setLocal EnableDelayedExpansioncall :YMD8 && cls
echo xcopy /s "c:\documents and settings" x:\%dat%-%month%-%year%\
goto :eof
::====== YMD8 ==========
:YMD8
@echo off > d.d
>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Qdebug < d.d > nul
del d.ddat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%del day.com
del month.com
del year.com
del dat.com
::== DONE
=====================================
If at first you don't succeed, you're about average.M2

Hi,
unfortunately using the %date% command as the variable on most O/S's using '/' (forward slashes) which aren't a valid folder name. So I would reccomend that before you run the XCOPY command, you create a folder like below...
mkdir %date:~0,2%-%date:~3,2%-%date:~7,4%
It looks a bit complicated, but it's basically filtering the output from the %date% system variable. For example, If i do Echo %date% on my system, the output is 21/07/2008 so the first part %date:~0,2% Is the %date% variable but only the 1st and second number (0 = first number, and I want the first 2 numbers, hence the ,2)
So your script would look similar to this
@echo off
Echo Backing up Files!!!
mkdir %date:~0,2%-%date:~3,2%-%date:~7,4%
XCOPY C:\Files to Backup USB:\%date:~0,2%-%date:~3,2%-%date:~7,4%It doesn't matter what date you run it on, the files will go into a folder for the current date. :)

That will work if you have guessed the date layout correctly.
That's why I get the date from BIOS.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |