- 1 year ago
Bulk rename files using part of existing filename
You can use a Windows batch script to bulk rename files by extracting a part of the existing filename and appending it to a new name. Here's an example batch script that demonstrates how to do this:
batch@echo off
setlocal enabledelayedexpansion
set "sourceDir=C:\path\to\source\folder"
set "targetDir=C:\path\to\target\folder"
set "searchText=_part_to_extract_"
for %%F in ("%sourceDir%\*%searchText%*") do (
set "filename=%%~nF"
set "extension=%%~xF"
set "newFilename=!filename:*%searchText%=!"
echo Renaming "%%~nxF" to "!newFilename!!extension!"
ren "%%~fF" "!newFilename!!extension!"
move "!newFilename!!extension!" "%targetDir%"
)
endlocal
Replace C:\path\to\source\folder
with the path to the folder containing the files you want to rename. Replace _part_to_extract_
with the part of the filename you want to remove. Replace C:\path\to\target\folder
with the path to the folder where you want to move the renamed files.
This script iterates through files in the source directory that contain the specified search text. For each file, it extracts the part of the filename before the search text and renames the file accordingly. The renamed file is then moved to the target directory.
Remember to test this script on a small set of sample files before applying it to a large batch of files to ensure it works as expected.