- 1 year ago
Edit text after dot with batch script
If you want to edit text after a dot (period) in a filename using a batch script, you can achieve this using the built-in string manipulation capabilities of the Windows command prompt. Here's an example script that demonstrates how to rename files by appending "_new" to the part of the filename after the dot:
batch@echo off
setlocal enabledelayedexpansion
rem Set the directory where the files are located
set "directory=C:\Path\To\Your\Directory"
rem Iterate through the files in the directory
for %%F in ("%directory%\*.txt") do (
set "filename=%%~nF" rem Get the file name without extension
set "extension=%%~xF" rem Get the file extension
rem Concatenate the new filename with "_new" and the original extension
set "newfilename=!filename!_new!extension!"
rem Rename the file
ren "%%F" "!newfilename!"
)
Replace "C:\Path\To\Your\Directory"
with the actual path to the directory containing the files you want to rename.
This script uses the for
loop to iterate through all .txt
files in the specified directory. It extracts the filename without extension and the file extension using the %%~nF
and %%~xF
syntax. Then, it concatenates the new filename with "_new" and the original extension. Finally, it renames the file using the ren
command.
Make sure to test this script on a small set of files before applying it to a larger set to avoid accidental renaming or data loss.