BAT file to change file name

This is probably not the right forum but I'm not sure where to put this...

I'm looking for a BAT file to look at a drive folder and change the file name by adding a timestamp at the end of the filename...

For example, I have c:\folder1\myfile.csv.
I want to change it to c:\folder1\myfile20110923.csv

Never done a BAT file!
LVL 8
CamilliaAsked:
Who is Participating?
 
jsdrayConnect With a Mentor Commented:
echo off
cls

set MyDir=c:\temp\test

for /r %MyDir% %%i in (*.*) do (
call :doitnow %%i %%~ni %%~dpi %%~xi
)
goto eof

:doitnow
set MyFile=%1
set MyFileNameOnly=%2
set MyFilePath=%3
set MyFileExt=%4
RENAME %MyFile% %MyFileNameOnly%%date:~-4,4%%date:~-7,2%%date:~-10,2%%MyFileExt%
:eof
0
 
jsdrayCommented:
What time are you wanting?  A hard coded time? The current time? or the File attribute time?
0
 
CamilliaAuthor Commented:
current time
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
brutaldevCommented:
http://www.intelliadmin.com/index.php/2007/02/create-a-date-and-time-stamp-in-your-batch-files/

For a simple one liner use this:
 
REN c:\folder1\myfile.csv c:\folder1\myfile%date:~-4,4%%date:~-7,2%%date:~-10,2%.csv

Open in new window

You can use patterns in the REN command (rename) as well. Put that line in a .bat file and you're good to go.
0
 
jsdrayCommented:
My last post will walk a tree for you...just change the MyDir Variable to the top level...  
0
 
CamilliaAuthor Commented:
thank you. I will try
0
 
CamilliaAuthor Commented:
going to try this now, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.