# How do I get DOS to make it's own file name



## smwabill (Apr 8, 2003)

I am using XP and would like to create a batch file in DOS to make a copy of my file smith.mdb but each time use a different name.

For example:

On Monday the batch file copies smith.mdb, then it creates a file of its own name choosing

On Tuesday the batch file copies smith.mdb and creates a different name than it did on Monday an so on.


The reason for this is I am making backup copies to a cdr and they can't have the same file name and I can't change the original file name because it is opened by a function key, so at the end of every day I have to copy the file and paste it and then copy it to my cdr. It would be far easier to make a batch file to do this. I use to know how many years ago but I've been out of DOS for a long time, but have always thought DOS was pretty good.

Thanks for your help
smwabill


----------



## vidmac (Apr 28, 2003)

Try this in your batch file:


@echo off
REM filename: dobak.bat
REM usage: dobak date
REM example: dobak 280403
if exist d:\smith%1.mdb goto error
copy smith.mdb d:\smith%1.mdb
goto end
:error
echo ERROR! - FILE ALREADY EXISTS
:end


"D:\" is the target path where you want to put the file, and "%1" is the first thing you type after the batch file name.

Then you could use the date to differentiate the files

so for today, you'd type: dobak 280403

Hope this helps


----------



## smwabill (Apr 8, 2003)

Thank you for your help

Very much appreciated.

smwabill


----------



## mole (Aug 24, 1999)

Since this is for NT/2K/XP, batch file between the ===:

=============================
for /f "tokens=2-4 delims=/ " %%a in ('DATE /T') do set DATE=%%a%%b%%c

copy smith.mdb %DATE%.mdb

=============================

Will set the file to copy the original to with the date. Rearrange the %%a%%b%%c if you want your date in another format.

mole


----------



## smwabill (Apr 8, 2003)

Thanks for your help. I will try it out as soon as I am able to.

Again thanks for your help.


smwabill


----------

