Renaming Files

G

Guest

Anyone have a method for looping through a folder and renaming a file based on
a criteria.

I don't necessarily need the dir loop. But how do you rename something, much
less based on a criteria? Use a .filesearch object

For example, say I have things called October Report.doc, October Sales.xls.
October Song.mp3

I don't want to open them just rename the files from Oct to Nov Report.doc,
October Sales.xls, etc

I just want to replace part of the name based on a search criteria. Possible?
[email protected]
 
P

patrick Molloy

loop through the dirrectory..

Dim FN as string, MyPath As String
MyPath = "C:\Temp\FolderX\"
FN = DIR(MyPath & "*.*")
DO UNTIL FN=""
If FN LIKE ("Nov*.*) Then
Rename MyPath & FN, MyPath & "Dec " & Mid(FN,4)
End If
FN = DIR
LOOP



Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Anyone have a method for looping through a folder and renaming a file based on
a criteria.

I don't necessarily need the dir loop. But how do you rename something, much
less based on a criteria? Use a .filesearch object

For example, say I have things called October
Report.doc, October Sales.xls.
 
Top