Windows batch file rename multiple files
::This function splits off the last `_`-separated item of a string. :GET_LAST_ITEM rtn_last rtn_without_last val_string
Rem // Enable delayed expansion to be able to read the variables: Rem // Call sub-routine that removes the last `_`-separated part: Rem // Store current file name and extension: Setlocal EnableExtensions DisableDelayedExpansionįor /F "delims= eol=|" %%F in ('dir /B /A:-D "%_SOURCE%\%_MASK%"') do ( Note that this fails in case any of the files contains exclamation marks ! in their names. Here is a modified script that I posted in another answer, relying on a nice hack to remove the last portion of a string separated by a certain character – the underscore _ in this case. The last string assigned to %%b will be _laststring.ext, so the value assigned to newname will fit the processing requirement, so rename the file. Select all the files you wish to rename (use Shift or Ctrl to select multiple files). In the example below, the folder contains 13 photo files with the names they were given by the camera they were taken on. Use a simple for to assign newname to the original filename with the _string removed (replaced by nothing) and add back the extension using %%~xa. Open the folder containing the files you want to rename. WIth each name found, using delayed expansion, assign the name to filename and then replace each _ with Space_ Perform a directory scan of all filenames matching the mask. After you've verified that the commands are correct, change ECHO(REN to REN to actually rename the files. The required REN commands are merely ECHOed for testing purposes. You would need to change the setting of sourcedir to suit your circumstances. Simply select multiple files, right click on the first one and click Rename.
#WINDOWS BATCH FILE RENAME MULTIPLE FILES WINDOWS#
FOR %%b IN (!partsname!) DO SET "newname=!filename:%%b=!%%~xa" Windows File Explorer has some (very limited) capacity to batch rename files.