I want to rename a large number of files in increasing order of numbers, starting from anywhere.
But when I rename multiple files, it leaves me with parentheses.
eg i rename files to abc_.jpeg it results in abc_(1).jpeg, abc_(2).jpeg and so on.
I tried using command prompt to rename
ren abc_(*).jpeg abc_*.jpeg
doesn't work. probably because of brackets
ren abc_"("*")".jpeg abc_*.jpeg
renames the files, but results in the same file name as before.
I just want to remove the parentheses somehow.
To remove the brackets you will have to do some string manipulation. I have written a batch file to do this (save as .bat
)
cd C:\folder
setlocal enabledelayedexpansion
for %%a in (abc_*.jpeg) do (
set f=%%a
set f=!f:^(=!
set f=!f:^)=!
ren "%%a" "!f!"
)
I don't think you can easily do this in one line from the command line though, it may be possible but it won't be pretty. If you can help it use this batch file to remove the brackets.
In the File Explorer window, select all files, right-click and select rename. Windows will select the starting number as the number supplied between the round brackets so name the file using a number that is 1 digit more than the number of digits required.
Example: We want the pattern "test_xxx". Using the File Explorer, rename the files to "tes(1000)". Your files will now be named ["tes(1000)", "tes(1001)", "tes(1002)", etc..]. Hold SHIFT and right click in the open area of the File Explorer, then choose "Open command window here". Issue the following command:
ren *.* test_???.*
This will rename all the files to the proper format ["test_000", "test_001", "test_002", etc..].
A bit late to the party, but here's a combination of removing parentheses and the empty space automatically created. This code works by having the .bat file inside a folder containing all the files you'd like to modify.
Copy and paste the code in notepad and save it as sequentialFileNameCleaner.bat
Your file name must be the same as what is written on the first line sequentialFileNameCleaner.bat. That being said, you can manually update the first line if you want to change the file name.
:sequentialFileNameCleaner [/R] [FolderPath]
setlocal enabledelayedexpansion
for %%a in (*.jpg) do (
set f=%%a
set f=!f:^(=!
set f=!f:^)=!
ren "%%a" "!f!"
)
@echo off
setlocal disableDelayedExpansion
if /i "%~1"=="/R" (
set "forOption=%~1 %2"
set "inPath="
) else (
set "forOption="
if "%~1" neq "" (set "inPath=%~1\") else set "inPath="
)
for %forOption% %%F in ("%inPath%* *") do (
if /i "%~f0" neq "%%~fF" (
set "folder=%%~dpF"
set "file=%%~nxF"
setlocal enableDelayedExpansion
echo ren "!folder!!file!" "!file: =!"
ren "!folder!!file!" "!file: =!"
endlocal
)
)
By default, this code will only locate .jpg files. On the 3rd line, changing the (*.jpg)
to (*.png)
or to (*.mp4)
or any extension you'd like will make the code compatible.