Batch file to put create date

Microsoft Windows xp professional editio...
September 13, 2009 at 02:48:56
Specs: XP
Hi, need some help creating a batch file. I've seen one
solution on here but I can't seem to get it to work.

What I need is a batch file that will put the CREATE
date and time (including seconds) at the beginning of a
file name while preserving the original file name.

So for example:
test.msg -> 09132009_0436_test.msg

Again I've already tried the suggestions in forum post

but was unsuccessful.

Please help
thank you

See More: Batch file to put create date

Report •

September 13, 2009 at 06:00:45
Just as in that high mileage thread you referenced, nothing gets done until we know the output of:


Helping others achieve escape felicity


Report •

September 13, 2009 at 08:48:24
Okay Dos can not help you with this. You need two extra Unix programms called AWK and GREP

Here is a link were you can download them:

awk.exe and grep.exe must be in a folder which is in the PATH so be smart and take c:\windows\system32

start.bat in the folder where you want to change the filenames !

Also in Bin.rar you will find a batchfile called start.bat

That will do what you want !!

Let me explain the working AND PAY VERY GOOD ATTENTION TO THE SYNTAX !

first line

dir /TC /A-d |grep -e ":"|grep -e "-"|awk {sub(/:/,"\"-"\");print}|awk {print\"ren\","$4,\"\"$1\"-\"$2\"-\"$4"}>>"select.bat"

dir /TC /A-d : will dir the folderlisting date-time -size filename and the header and bottom text

grep -e ":" and grep -e "-" will cut of the extra info (header and bottom text SO NOW WE HAVE ONLY FILE INFO)

awk {sub(/:/,"\"-"\");print}| In the time notation the seperator is : and that is not allow in a file name by DOS.
So we substitute it for -

awk {print\"ren\","$4,\"\"$1\"-\"$2\"-\"$4"}

Look at DIR /TC /A-d output

$1 is date colomn
$2 is time column
$3 is files size (don't need that) column
$4 is filename column

we now make each line change in:

ren oldfilename date-time-oldfilename

ren is from rename

these lines are stored in a batchfile called "select.bat"

then select.bat is called and wil change the filenames


your start.bat will also be renamed RENAME IT BACK

if you want to change the line : dir /TC /A-d |grep -e ":"|grep -e "-"|awk {sub(/:/,"\"-"\");print}|awk {print\"ren\","$4,\"\"$1\"-\"$2\"-\"$4"}>>"select.bat"

MAKE SURE OF 1 THING !!!!!!!!!!!!!!!

You can not start start.bat from a dos box (command line command) that will not work in XP or VISTA DOS (CMD)

Go to explorer and klik on the start.bat file

I tested it and it ran great


Report •

September 14, 2009 at 00:40:01
This has nothing to do with DOS.

There is no 'created date' in DOS.

And I doubt that it will require awk & grep.

Let's see if OP provides the info requested.

Helping others achieve escape felicity


Report •

Related Solutions

September 14, 2009 at 00:55:15
I actually got something working that will do just fine.

FOR %%V IN (*.msg) DO FOR /F "tokens=1-5 delims=/: " %%J IN ("%%~tV") DO IF EXIST
%%L%%J%%K_%%M%%N%%~xV (ECHO Cannot rename %%V) ELSE (Rename "%%V" %%L%%J%%K_%%M%%N%%~xV)

That renames the file to the create date. So it just places the create date in place of the file name. So far it works great.

Thanks for the help. Oh and I can't download or install any programs, hence the reason I'm using batch files instead of perl or python or anything else that's infinitely more powerful than a batch file.


Report •

September 14, 2009 at 01:10:18
I don't think %%~Tv gets you time created.

But, whatever gets you through the night.

Helping others achieve escape felicity


Report •

September 14, 2009 at 02:06:13
Well I know it works. I created a file named test.msg at 4 am
and I ran the batch file the file was renamed to

Maybe it's using the modified date, but whatever it's using it
works. :)

Report •

September 14, 2009 at 03:18:59
I'm pretty sure it's using mod date.

Helping others achieve escape felicity


Report •

September 14, 2009 at 03:49:24
Yeah it's using the mod date which I guess is all I need it to
do. Thanks again for your help and suggestions. :)

Report •

September 14, 2009 at 14:17:43
Doesn't matter how you do it as long as you get YOUR Result

If you want to do more of this file manipulation things you should have a look into the UNIX tools they are much powerful than all the stuf you can do with DOS.

Almost all the unix tools are also available in Win32, they just have some minor syntax differences.

Report •

September 14, 2009 at 16:33:04
I would love to use Unix but this my work computer and I'm
very limited in what I can do. I would rather use a perl or
even python script to get my results but I'm not allowed to
load any software. :(

Oh well, I'll get by with what I have for now.


Report •

Ask Question