Discussion Locked

simple bat question

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I want to use a simple batch file to copy the "same" .mdb file that is created each day. I would like to rename the file with the current date. How do I do this?

9 replies

by fgarber

A batch file can't do what you want. You will have to use some kind of scripting language. Windows Scripting Host works very well, is free and there is great documentation at msdn.microsoft.com/scripting. There is also a good article on this site titled adminrepublic scripting primer.
click on downloads then tools and executables.
The article is about the 4th or 5th one down.

by mtadeu

If you're using MS Access, you should try creating a new Module and take a look at the "MakeReplica" method( the example is quite explicit ). If you'd like to try VB( if you have a development enviroment ), maybe you'd like to take a look at the CopyFile method from the FileSystemObject.

Good luck,
Miguel Tadeu

by zalog

1) Create a text file using using notepad that contains a single ENTER keystroke. Save this file as CR.TXT.

2) Create a batch file using notepad that contains the rename command:

REN c:\path\file.mdb %4.mdb

"c:\path\file" should be replaced with the actual drive, path and filename. Save this file as CURRENT.BAT.

3) Create a batch file that contains the follwing two commands:

date < cr.txt > dateout.bat
dateout

Save this file as RENMDB.BAT.

4) Now at the DOS command line type RENMDB and the file will be renamed as the date.

Note: For this to work all files created in steps 1-3 must be in the same folder. The current path must be this folder before executing step 4. You may want to create a new folder for these files.

How this works: The batch file RENMDB.BAT executes the DATE command using redirection. Since this command needs user input to continue we created the CR.TXT file to send an ENTER to this command. The output from this command creates/overwrites a file called DATEOUT.BAT. The batch file calls this DATEOUT.BAT. The DATEOUT.BAT files' first line contains the text "Current date is WED 04-18-2001". We created a batch file called CURRENT.BAT in step 2. DATEOUT.BAT calls CURRENT.BAT and passes "date is WED 04-18-2001". CURRENT.BAT uses the forth parameter (%4), which is the date, to rename the file.

It's a round about way of doing things, but it does work.

Email or post a reply here if you need assistance with geting this working.

by emcs

ENVTIME is a freeware program, and can be found at: http://www.bookcase.com/library/software/msdos.util.batch.html.

ENVTIME can create a file with the date and time that the file is copied. You can schedule the job to run every day or night at the same time. You need to read the help file with ENVTIME for exact syntax you require.

I have used ENVTIME to create directories and file based on the system date.

Good luck.

dennie

This discussion is closed to new replies.