Created
July 14, 2010 16:57
-
-
Save JoshMock/475676 to your computer and use it in GitHub Desktop.
Given a folder full of files, replaces one string for another in each file name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Results: Looks at the names of all files in FOLDER_TO_SCAN, replacing any instance of STRING_TO_REPLACE with REPLACE_WITH in each filename. | |
Dim FOLDER_TO_SCAN, STRING_TO_REPLACE, REPLACE_WITH | |
FOLDER_TO_SCAN = "C:\Folder\to\scan\" | |
STRING_TO_REPLACE = "replace this" | |
REPLACE_WITH = "with this" | |
Dim fso, folder | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
Set folder = fso.GetFolder(FOLDER_TO_SCAN) | |
For Each subfolder In folder.SubFolders | |
If Instr(subfolder.Name, STRING_TO_REPLACE) > 0 Then | |
subfolder.name = Replace(subfolder.Name, STRING_TO_REPLACE , REPLACE_WITH) | |
End If | |
Next | |
For Each file In folder.Files | |
If Instr(file.Name, "#") > 0 Then | |
file.name = Replace(file.Name, "#", "") | |
End If | |
Next | |
Set fso = Nothing | |
Set folder= Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment