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?
(e-mail address removed)
 
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.
 
G

Guest

It didn't like

If FN LIKE ("Nov*.*) Then

Is the LIKE command valid?
(e-mail address removed)
 
G

Guest

Thanks. I'm trying to put together a system of find and replace with filenames.
Still working on it.
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top