Append datestamp to all files in a directory

I need a script that will allow me to append the datestamp of each file in a directory to each filename.  For example;

Name                                                         Date Modified
test1.txt                                                      6/18/2013
Joeresume.doc                                            7/12/2013

Would become;

Name                                                         Date Modified
test1_20130618.txt                                                6/18/2013
Joeresume_20130712.doc                                      7/12/2013
KMKellerAsked:
Who is Participating?
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.

jmcmillan227Commented:
Function GetDateTimeStamp
  Dim strNow
  strNow = Now()
  GetDateTimeStamp = Year(strNow) & Pad2(Month(strNow)) _
        & Pad2(Day(StrNow)) & Pad2(Hour(strNow)) _
        & Pad2(Minute(strNow)) & Pad2(Second(strNow))
End Function

Function Pad2(strIn)
  Do While Len(strIn) < 2
    strIn = "0" & strIn
  Loop
  Pad2 = strIn
End Function
0
Bill PrewCommented:
Here's a simple small BAT script that should do the job.  It assumes your date format is MM/DD/YYYY, if it isn't we can adjust for that.

Save as a BAT file and adjust the folder name near the top to be the location of the files to rename.  Currently I have the actual REN command with an ECHO in front of it.  SO when you run it for testing it won't actually rename the files, but will just display the rename command it would execute.  This will allow you to verify you are getting the naming you want.

Once it looks good in test mode, remove the word ECHO in front of the REN, and run for real.  Only run it once for real in the folder, or else you will get the date appended multiple times.

@echo off
setlocal EnableDelayedExpansion

set BaseDir=c:\EE\EE28244069\Files

for %%F in ("%BaseDir%\*.*") do (
  set Stamp=%%~tF
  set Stamp=!Stamp:~6,4!!Stamp:~0,2!!Stamp:~3,2!
  ECHO ren "%%~F" "%%~nF_!Stamp!%%~xF"
)

Open in new window

~bp
0

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
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
VB Script

From novice to tech pro — start learning today.