ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming Files (https://www.excelbanter.com/excel-programming/277502-renaming-files.html)

Spammastergrand

Renaming Files
 
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?


patrick molloy

Renaming Files
 
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.
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?

.


Spammastergrand

Renaming Files
 
Thanks. Sounds great.


Spammastergrand

Renaming Files
 
It didn't like

If FN LIKE ("Nov*.*) Then

Is the LIKE command valid?


Tom Ogilvy

Renaming Files
 
try

name oldname as newname

--
Regards,
Tom Ogilvy

Spammastergrand wrote in message
...
Didn't like Rename.
Do I need to add a reference to a windows API or something? It doesn't
recognize it as a keyword or method.




Spammastergrand

Renaming Files
 
Thanks. I'm trying to put together a system of find and replace with filenames.
Still working on it.



All times are GMT +1. The time now is 03:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com