XCOPY to backup/rename file

Hello, I need help creating a bat file that will copy a file on a local machine to a network drive.  I have an access database called WORKORDER.MDB right on the C drive of the local machine, I want to copy this access database to H:\Backup\.  I want to maintain the original file name, but time stamp it with date/time.  Example  WORKORDER_11/03/2008 11:34:34 AM.MDB or something close to that.  Can someone help me out?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Put the first block of code in databasecopy.vbs preferably saved on the computer where the .mdb is located

The second 2 line block goes in a .bat file in the same directory as the vbs file, which calls the vb function passing 2 arguments.  File and directory to copy and what directory/filename to save it as.

Then you could even take it one step further and define a windows "scheduled task" to run the backup routine at intervals like every night at 3am or something.

On Error Resume Next
Dim strCopyFile, strCopyTo, FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
strCopyFile = WScript.Arguments.Item(0)
strCopyTo = WScript.Arguments.Item(1)
If FSO.FileExists(strCopyFile) AND FSO.FolderExists(strCopyTo) Then
	Dim objCopyFile
	Set objCopyFile = FSO.GetFile(strCopyFile)
	  FSO.CopyFile strCopyFile, strCopyTo, True
	Set objCopyFile = Nothing
End If
Set FSO = Nothing
echo Copying "filename.mdb" ...
wscript databasecopy.vbs "C:\folder\filename.mdb" "C:\folder\backups\"

Open in new window

Paste the script below into a text file with a .cmd extension.  Customize the value of the db variable with the location of the database to be copied.  Running the script will copy and rename the file.

@echo off
set db=c:\files\workorder.mdb
set dest=h:\backup
set stamp=%date:~10,4%%date:~4,2%%date:~7,2%-%time:~0,2%%time:~3,2%%time:~6,2%
for /F "tokens=*" %%G in ('dir "%db%" /B /S') do echo F|xcopy "%%G" "%dest%\%%~nG_%stamp%%%~xG"

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
holemaniaAuthor Commented:
Thanks.  Just looking for something like Shift-3 provided.  Just need to create a bat file that will copy the file and put a date with it and save it to a location.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.