# DOS Batch File..



## yuppicide (Jul 21, 2005)

We're using Windows NT here at work and I want to make a batch file to simplify our daily backups.

Is there a way to make the batch file automatically take todays date and make that the name of a .zip file? Here's the batch file I made so far:


```
"wzzip m:\Navision Backup\*.fbk"
"copy m:\Navision Backup\*.zip r:\Daily Navision Backup"
If ErrorLevel 1 Goto ErrMsg
Echo No Known Errors
Goto Exit
:ErrMsg
Echo *** ERROR DETECTED ***
:Exit
"del m:\Navision Backup\*.fbk"
Echo Backup copy completed successfully.
pause
Echo Type EXIT to return to Windows.
```
1 - As you can see in the code, this batch file runs WinZip's command line program. I would like it to automatically name it after the date (examples: 120705.zip or 120805.zip).
2 - It then copies the zip file over to our R: drive where all the backups are stored.
3 - If there are no errors it deletes the fbk file and displays messages to the user.

How can I get it to automatically name the zip file?! If that is not possible how can I get it to ask the "Enter Backup Date (ex: 120705):" and it will take that input and save it as that + .zip at the end?! So if the user enters 120705 it'll name it 120705.zip


----------



## Millsy (Feb 4, 2005)

You might be able to modify this to rename the files. Or just use the folders like this idea has.

http://www.speedguide.net/read_articles.php?id=1547



```
Using the Current Date

Sometimes it is useful to create folders with the date incorporated in the folder name. Here is how to set the variable folder to the current date (assuming US system date format):

set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
%backupcmd% "...source dir..." "%drive%\%folder%\...destination dir..."

It is also possible to use the current time in the folder name. The following example with incorporate both the current date and time to the minute, separated by underscores. There is an extra step that cleans up possible spaces in single-digit hours in the system time:

set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%
%backupcmd% "...source dir..." "%drive%\%folder%\...destination dir..."
```


----------



## yuppicide (Jul 21, 2005)

Thanks for the help so far. I haven't managed to get anything to work yet tho. I keep getting different error messages.


----------



## mandrews1234 (Jan 7, 2008)

I can help you it took me a while to figure this out. I don't know what the name of your .zip file is but lets say its temp.zip type the command 
ren temp.zip %date:~4,2%%date:~7,2%%date:~10%.zip and that should give you the format mmddyyyy you can put underscores or hyphens between the %% if you want mm-dd-yyyy. also if your file is in a different path just specify it. I.E. your file is in c:\test and its name is temp.zip
type ren c:\test\temp.zip and then the date things. Hope this helps


----------

