Solved

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

Posted on 2010-09-09
2
228 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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