Solved

Batch rename files (specific date format) in windows xp explorer

Posted on 2010-09-09
2
224 Views
Last Modified: 2012-08-13
I have several hundred files that have names that include dates, in either YYYY-MM-DD or YYYYMMDD format.  I need to batch find and replace these dates to convert them to MMDDYYYY.  But also, to move the date to the end of the file name, with a space prior to the date So for instance:

1989-06-19-COMPANY-COMPANY-SPCC GEN INFO.TIF

would be renamed:

COMPANY-COMPANY-SPCC GEN INFO 06191989.TIF


20100809 - Remed - Stantec - HASP for GWM.pdf

would be renamed

- Remed - Stantec - HASP for GWM 08092010.pdf


Thank you in advance,

Anthony
0
Comment
Question by:antimel
2 Comments
 
LVL 3

Accepted Solution

by:
ia2189 earned 500 total points
ID: 33640439
Be sure to make a backup copy of your files as the below code will delete the original files.  I tested the code given your two examples and it ended with the desired results.

- Copy and paste the below code into Notepad.
- Change the [YOUR FOLDER PATH HERE] to be the location of the folder where your files are stored
- From Notepad, save the document as a .txt file
- Go to where you saved the .txt file and change the extension from .txt to .vbs
- Double-click the .vbs file to run it
- A message box will appear when completed.

Dim fso
Dim oFolder
Dim oFile
Dim sNew
Dim sExt

Set fso = CreateObject("Scripting.FileSystemObject")

Set oFolder = fso.GetFolder("[YOUR FOLDER PATH HERE]")

For Each oFile In oFolder.Files

   If IsNumeric(Mid(oFile.Name, 1, 8)) Then 'Example two in question

      sExt = Right(oFile.Name, 4)

      sNew = LTrim(Mid(oFile.Name, 9))
      sNew = Replace(sNew, sExt, "") & " "
      sNew = sNew & Mid(oFile.Name, 5, 2)
      sNew = sNew & Mid(oFile.Name, 7, 2)
      sNew = sNew & Mid(oFile.Name, 1, 4)
      sNew = sNew & sExt

      oFile.Copy oFolder.Path & "\" & sNew, True
      oFile.Delete True
         
   ElseIf IsNumeric(Mid(oFile.Name, 1, 4)) Then 'Example one in question

      sExt = Right(oFile.Name, 4)

      sNew = LTrim(Mid(oFile.Name, 12))
      sNew = Replace(sNew, sExt, "") & " "
      sNew = sNew & Mid(oFile.Name, 6, 2)
      sNew = sNew & Mid(oFile.Name, 9, 2)
      sNew = sNew & Mid(oFile.Name, 1, 4)
      sNew = sNew & sExt

      oFile.Copy oFolder.Path & "\" & sNew, True
      oFile.Delete True

   End If
   
Next

MsgBox "Process complete!"
0
 
LVL 1

Author Closing Comment

by:antimel
ID: 33641363
That was amazing and will save me so much time.  Thank you so much.

Anthony
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now