I need help for a batch script. I've tried a few codes, but most are based on renaming from a set constant (since 1 and with only two or three digits) but I want the sequence begin from whatever number is enter with set /p (eg "026"). Also, the other problem is that the names of files are only numbers and I need to correct the sequence since where it begin.
+ Reply to Thread
Results 1 to 24 of 24
-
-
I use a file manager called total commander.
It has some fantastic options in file renaming.
Sent from my SM-A705FN using Tapatalk -
Just google "batch renamer". There are a bunch of utilities that should be able to do what you want.
Scott -
-
If you can live with numbers in parentheses:
https://answers.microsoft.com/en-us/windows/forum/windows_7-files/renaming-files-in-se...9-b1a5b38bdc23Last edited by jagabo; 3rd Aug 2020 at 11:57.
-
At least there should be a way to remove these parentheses without modifying the rest, but it would be a separate process and that is not the idea.
-
I have a program called MassRaname that can do this. If you can't find it, I can upload the install file
-
>MassRaname
Such a name would put to the batch file what I need. As I said, if is an GUI and it also requires installation, it's not what I'm looking for. -
Here's one way do do it in a batch file:
Code:setlocal enabledelayedexpansion set num=99 for %%f in (*.jpg) do ( ren "%%f" "NewName!num!.jpg" set /a num=!num!+1 ) endlocal
-
-
Precisely is one of the problems that I mentioned in the first post. It is common to find codes that set a constant, not a variable that I enter with set /p and avoid edit the bat every time. Also, how would the batch know if the sequence I'm trying to reorder consists of changing names that are already in the same directory? For example, the first file is called "024", but I want to change it to start from "026" and so on the rest. I think the same name conflict can be avoided with a temp directory but I'm not sure. About leading zeros, that's another headache but it sure must have some solution, too.
-
You could have DL'd https://www.1-4a.com/rename/ and been done by now and would be able to reuse for any other of your listed scenarios.
Scott -
-
Do you realize you can pass arguments to a batch file the same way you pass arguments to any command line program? For example, change "set num=99" in the batch file to "set num=%1" to set the starting number of the new files to whatever you specify with the first argument on the command line.
The script as I gave it gives the files new names to avoid naming conflicts. Of course you can also avoid conflicts by moving/copying the output files to another folder. Just add the folder name to the output filename spec. You can even modify the batch file to use a folder name specified on the command line. -
I mean at what point in the script is when the name change is as I need? That script does an automated rename starts "1" and that's not the goal, I mentioned the idea in the same post.
Sorry if I don't explain properly but I can't when English is not my language, I also know little about using batch files and I get so confused. -
-
I had some time to work on a few parts that I didn't know how to do. This batch file lets you specify the starting number of the source files, the ending number of the source files, and the starting number of the output files. It also lets you specify the input base name and output base name (both can include folder paths). All five arguments are required.
Code:@echo off REM Copies numbered sequences of files with renumbering. Expects REM five digit numbers. Can easily be modified for more or fewer digits. REM REM Renum InBase First Last OutBase OutNum REM REM InBase: is the base (without digits) filename of the source images. REM If the filename has only digits you can use ".\" (current folder) REM or the path to the files "X:\folder\name\" REM REM First: Is the number of the first file to copy/rename. REM REM Last: Is the number of the last file to copy/rename. REM REM OutBase: Is the base (without digits) filename for the REM Output files. You can use a full pathname or REM a relative path. The folder should exist before REM calling this batch file. REM REM OutNum: Is the number for the first output file. REM REM REM Usage: Renum Pic 0 11 new\New 101 REM REM File of the form Pic00000.png, numbered from 0 to 11, are REM copied to a folder called New and named New00101.png REM New00102.png, etc. REM REM Usage: Renum .\ 8 11 new\ 101 REM REM Files of the form 00000.png, numbered from 8 to 11, REM are copied to a folder called New and named with REM the form 00101.png REM REM The trick for adding leading zeros comes from: REM https://stackoverflow.com/questions/9430642/win-bat-file-how-to-add-leading-zeros-to-a-variable-in-a-for-loop setlocal EnableDelayedExpansion set InBase=%1 set first=%2 set last=%3 set OutBase=%4 set OutNum=%5 for /L %%i in (%first%, 1, %last%) do ( REM build input filenames set "Informatted=000000%%i" set InName=%InBase%!InFormatted:~-5!.png REM build output filenames set "Outformatted=000000!OutNum!" set OutName=%OutBase%!OutFormatted:~-5!.png copy !InName! !OutName! REM Use move instead of copy if you don't want to keep the original files in place. set /a OutNum+=1 ) endlocal
-
I use Bulk Rename Utility from https://www.bulkrenameutility.co.uk. I use the installed version but it has portable and command line versions also.
-
-
-
-
You don't edit the file at all. You type the commands in a command line window.
-
Here's an update that can deal with spaces in the path and file names. Note especially the second sample command line.
Code:@echo off REM Copies numbered sequences of files with renumbering. REM REM Renum InBase First Last OutBase OutNum REM REM InBase: is the base (without digits) filename of the source images. REM If the filename has only digits you can use ".\" (current folder) REM or the path to the files "X:\folder\name\" REM REM First: Is the number of the first file to copy/rename. REM REM Last: Is the number of the last file to copy/rename. REM REM OutBase: Is the base (without digits) filename for the REM Output files. You can use a full pathname or REM a relative path. The folder should exist before REM calling this batch file. REM REM OutNum: Is the number for the first output file. REM REM REM Usage: Renum Pic 0 11 new\New 101 REM REM File of the form Pic00000.png, numbered from 0 to 11, are REM copied to a folder called New and named New00101.png REM New00102.png, etc. REM REM Usage: Renum "D:\Picture Sequence\" 8 11 "D:\Picture Sequence\New\" 101 REM REM Files of the form "D:\Picture Sequence\00000.png", numbered from 8 to 11, REM are copied to a folder "D:\Picture Sequence\New\" and renamed/renumbered REM starting with "00101.png" REM REM The trick for adding leading zeros comes from: REM https://stackoverflow.com/questions/9430642/win-bat-file-how-to-add-leading-zeros-to-a-variable-in-a-for-loop setlocal EnableDelayedExpansion set InBase=%1" set first=%2 set last=%3 set OutBase=%4 set OutNum=%5 set "InBase=%InBase:"=%" set "OutBase=%OutBase:"=%" for /L %%i in (%first%, 1, %last%) do ( REM build input filenames set "Informatted=000000%%i" set InName=%InBase%!InFormatted:~-5!.png set InName="!InName!" REM build output filenames set "Outformatted=000000!OutNum!" set OutName=%OutBase%!OutFormatted:~-5!.png set OutName="!OutName!" copy !InName! !OutName! set /a OutNum+=1 ) endlocal
-
(Above mentioned BRC program [from Bulk Rename Utility].)
Since you don't want to rename all the files in a directory, move the ones you want into a subdirectory.
Then run the command on that subdirectory (X, in my case).
Note that it looks like it is reading, renaming based on ASCII (sort) sequence.
The GUI version can do "Logical" (Natural) sorting.
I set the numbering to start at 26 (padded 3). Don't see why you couldn't set the start sequence number as a variable & pass your wanted starting value...
Code:T:\_from_Seagate\X>brc32.exe /removename /autonumber:26:1:P::10:3 /dir:x Processing Folder x\ Filename 1 would be renamed to 026 Filename 10 would be renamed to 027 Filename 11 would be renamed to 028 Filename 2 would be renamed to 029 Filename 23 would be renamed to 030 Filename 3 would be renamed to 031 Filename 33 would be renamed to 032 Filename 333 would be renamed to 033 Filename 5 would be renamed to 034
Similar Threads
-
running multiple files in sequence possible with ffmpeg?
By sommers in forum Newbie / General discussionsReplies: 6Last Post: 4th Jun 2017, 09:19 -
Rename files based on chapter title?
By NukeyDoo in forum Newbie / General discussionsReplies: 6Last Post: 6th Dec 2016, 02:48 -
Need Faster Way to Rename Video Files
By TwoRails in forum ComputerReplies: 8Last Post: 2nd Jun 2016, 10:32 -
Batch Rename Video Files
By TheRandomOne in forum Newbie / General discussionsReplies: 8Last Post: 22nd Jan 2016, 10:36 -
BATCH processing: rename files starting from the older? ndjamena help :-)
By marcorocchini in forum Newbie / General discussionsReplies: 17Last Post: 6th Dec 2015, 03:53