Renaming Files

  • Thread starter Thread starter Guest
  • Start date Start date
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?
(e-mail address removed)
 
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.
 
It didn't like

If FN LIKE ("Nov*.*) Then

Is the LIKE command valid?
(e-mail address removed)
 
Thanks. I'm trying to put together a system of find and replace with filenames.
Still working on it.
(e-mail address removed)
 
Back
Top