1.

Solve : add current date/time to filename?

Answer»

Hi there.

I have a batch file that runs a dts package against a txt file (extract.txt). The batch file runs 4 times a week. I used to just delete the extract file after the dts had finished but now I have to move the Extract file into a folder called E:\Extract\OLD.

my problem is that the extracts have to have the current DATE/time added to their file name, before they are put in the OLD folder, so that a collection of past extract files are stored in a folder, which can be viewed for reference. So what I need to do is rename the extract.txt so that the current date/time is added to the end of the file name:

eg extract.txt would RENAMED extract011120061534.txt (todays date and time)

and then move it into the old folder.

Is there a way of doing this within my current batch file so that the date/time is AUTOMATICALLY added to the file name.

Thanks in advance ps..im a novice at batch files, so please keep it simple if possibleDo you want to rename it with the current date and time? Or the date and timestamp of the file?

I am making the following assumptions: You are running Windows 2000 / XP / 2003 / Vista, your regional SETTINGS are U.S., English, and you want to use the preferred format of YYYYMMDDhhmm. Try:
Code: [Select]@echo off
setlocal
set hour=%time:~0,2%
if %hour% LSS 10 set hour=0%hour:~-1%
ren extract.txt extract%date:~-4%%date:~-10,2%%date:~-7,2%%hour%%time:~3,2%.txtIf you need a different format, post back and let us know.

If you just need to add the date to the filename (without time) it can be done in just 1 line of code.thanks I'll give that a try.

I get EMAIL an extract several times a week. Each time the extract has the same file name. Now I have to put the extracts in a folder called old, for referencing purposes I need the date/timestamp added to the filename, so that over a period of week, the "Oldfolder" will have files listed like thus:

extract110120061345.txt
extract110220061406.txtFour times a week? Then you don't need the time.

I suggest you change the standard for your history folder like this:
extract20061101.txt
extract20061102.txt

Namely, put the year first so at the end of the year
extract20061229.txt
extract20070102.txt
remain in order. Otherwise, all your Januarys will be together regardless of year.

Mac

This worked great!

Thanks.

Lorie



Discussion

No Comment Found