I presume you've got a lot of file names. 10, 100 or 1000?
- Start up command prompt (cmd.exe) and run as administrator.
- Go to directory where your files are. Let's presume C:\temp
- Type dir /b
- Look for the little black icon at the top left
- Choose Edit | Mark. You can now select your files.
- Choose Edit | Copy
- Go to Excel and start up a new workbook and select A1
- Hit Paste
Now suppose your file name is something like: Fortitude.S01E01.WEB-DL.XviD-FUM.jpg and you want to replace the part "
WEB-DL.XviD-FUM" with "
IMG_" (without quotes.)
- Go to B1 and enter formula =
SUBSTITUTE(A1
;"WEB-DL.XviD-FUM.jpg"
;"IMG_.jpg") Attention, I use semi colon and not comma because I have Dutch version.
- Copy down
- Now you have your correct file names in B1
- Copy and Paste this code in a new module -> Alt+F11 | Insert | Module
Code:
Sub RenameFiles()
Dim xDir As String
Dim xFile As String
Dim xRow As Long
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
xDir = .SelectedItems(1)
xFile = Dir(xDir & Application.PathSeparator & "*")
Do Until xFile = ""
xRow = 0
On Error Resume Next
xRow = Application.Match(xFile, Range("A:A"), 0)
If xRow > 0 Then
Name xDir & Application.PathSeparator & xFile As _
xDir & Application.PathSeparator & Cells(xRow, "B").Value
End If
xFile = Dir
Loop
End If
End With
End Sub
- Run the code by hitting F5
When you are prompted to select the correct directory, select C:\temp (when your files are in that directory!)