KOMPX.COM or COMPMISCELLANEA.COM   

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

  1. SET ss64.com/nt/set.html
  2. SETLOCAL ss64.com/nt/setlocal.html
  3. How to replace "=","*", ":" in a variable dostips.com/forum/viewtopic.php?t=1485
  4. Replacing text in file with an equal-sign in it dostips.com/forum/viewtopic.php?t=4718
  5. Using Windows ren command to remove ! from filename stackoverflow.com/questions/51861296/using-windows-ren-command-to-remove-from-filename
Operating systems
More