Remove a prefix from filenames in a folder
Removing a prefix from filenames in the current directory by FOR and REN commands from Windows Command Prompt. Code for .BAT file:
SETLOCAL EnableDelayedExpansion
REM Set your prefix to remove
SET "PREFIX=YOUR_PREFIX"
FOR %%G IN (*) DO (
SET "FILENAME=%%~G"
REN "!FILENAME!" "!FILENAME:*%PREFIX%=!"
)
Note: the code is not for cases, when filenames contain "=", equals sign.
Links
- SET ss64.com/nt/set.html
- SETLOCAL ss64.com/nt/setlocal.html
- How to replace "=","*", ":" in a variable dostips.com/forum/viewtopic.php?t=1485
- Replacing text in file with an equal-sign in it dostips.com/forum/viewtopic.php?t=4718
- Using Windows ren command to remove ! from filename stackoverflow.com/questions/51861296/using-windows-ren-command-to-remove-from-filename
Operating systems
- Windows