General
basic command is ren file1 file2
OR for files across nested folders ren path+file1 file2
create a *.bat file to batch rename all files
for files that have subfolder arrangement, include file path for old file name (file1)
tip: if spaces exist in filename must wrap filename within quotes
Steps
-
Open a Command Prompt window at your desired location : hold Shift, right-click in the folder, and select “Open command window here.”
-
Extract all filenames include path if needed:
-
When files are all in the same directory use command: dir /b >changename.bat and press Enter
-
For nested subfolders use command: dir /s /b /a-d >changename.bat and press Enter
-
Goto NotePad and Open changename.bat (change file types to view all)
-
From the menu select Edit>Select all, then Edit>Copy or press keys control + C
-
Goto Excel, paste data (may need to use text import wizard so data is not auto parsed)
-
Remove any files you do not wish to rename (e.g. thumbs.db)
-
Insert column to left, enter “ren” for all rows
-
In column to right of filenames, enter new filenames (see below for tips on converting filenames)
-
Select entire range (3 columns) and Copy
-
Toggle back to changename.bat in NotePad
-
Replace all lines: Edit>Select all>Paste
-
Save and close file changename.bat
-
Toggle back to command prompt and enter : changename.bat and press Enter
Figure 1: Command line Window: Extract filenames with path
Examples
You may use various features/formulas in Excel formulas to create new filenames. Below are two examples
Example: change case to all lower case
Eg from MSS58600005R.tif to ms58600005r
-
Open changename.bat in excel
-
Insert column to left, enter “ren” for all rows
-
In next empty column insert formula =lower(B1)
-
Copy and paste formula for all rows of data
-
Select entire range (3 columns) and Copy
-
Paste into changenames.bat file, save and run batch
Example: Use subfolder name as prefix to existing filename
Eg from 0005.tif to thr1916012901_0005.tif
-
Open changename.bat in excel
-
Insert column to left, enter “ren” for all rows
-
Parse out data
-
Selection column of existing filenames
-
From the Data menu, on the Data Tools Panel, select Text to columns
-
Wizard will appear. Select Delimited file type and press Next
-
Place a check mark next to the Other box and enter a back slash “\” as the deliminator and press Next
-
In Destination, enter the cell reference for the next first empty column (eg C1) in your spreadsheet and press Finished
This will parse out data into separate columns. Remove any columns you do not need
-
In this case, keep data for subfolder name which will be used to generate new filename
-
Column “ext” is formula (=right(B2,3). It is used only to help sort files and identify which ones do not need to be renamed (e.g. thumbnails)
-
Create new filename, using concatenate function:
Where New Filename is
=CONCATENATE("thr",F2,"_",G2)
Where F2 = folder name (eg 1913012901)
G2 = filename
-
Select entire range (3 columns) and Copy
-
Paste into changenames.bat file, save and run batch
Comments (0)
You don't have permission to comment on this page.