VideoHelp Forum
+ Reply to Thread
Results 1 to 24 of 24
Thread
  1. 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.
    Quote Quote  
  2. I use a file manager called total commander.
    It has some fantastic options in file renaming.

    Sent from my SM-A705FN using Tapatalk
    Quote Quote  
  3. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    Just google "batch renamer". There are a bunch of utilities that should be able to do what you want.


    Scott
    Quote Quote  
  4. Originally Posted by Cornucopia View Post
    Just google "batch renamer". There are a bunch of utilities that should be able to do what you want.


    Scott
    It's not like I haven't looked before asking. What I least want is to use some GUI that requires installation or something similar (unless it is portable), I thought it would be easier and faster to do it with a batch file but I can't find what I'm looking for.
    Quote Quote  
  5. Last edited by jagabo; 3rd Aug 2020 at 12:57.
    Quote Quote  
  6. 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.
    Quote Quote  
  7. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    I have a program called MassRaname that can do this. If you can't find it, I can upload the install file
    Quote Quote  
  8. >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.
    Quote Quote  
  9. 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
    The new files won't have leading zeros in the numbers though.
    Quote Quote  
  10. Member
    Join Date
    Mar 2008
    Location
    United States
    Search Comp PM
    Originally Posted by naoto89 View Post
    >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.
    Yes it is a GUI with installation but it can do all the files in a folder in one go
    Quote Quote  
  11. Originally Posted by jagabo View Post
    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
    The new files won't have leading zeros in the numbers though.
    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.
    Quote Quote  
  12. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    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
    Quote Quote  
  13. Originally Posted by Cornucopia View Post
    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
    And how does the name change as I need to? I don't understand the program interface.
    Quote Quote  
  14. Originally Posted by naoto89 View 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.
    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.

    Originally Posted by naoto89 View Post
    I think the same name conflict can be avoided with a temp directory
    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.
    Quote Quote  
  15. Originally Posted by jagabo View Post
    Originally Posted by naoto89 View 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.
    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.

    Originally Posted by naoto89 View Post
    I think the same name conflict can be avoided with a temp directory
    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.

    Originally Posted by naoto89 View Post
    The first file is called "024", but I want to change it to start from "026" and so on the rest.
    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.
    Quote Quote  
  16. Originally Posted by naoto89 View Post
    The first file is called "024", but I want to change it to start from "026" and so on the rest.
    You could move files 000 to 023 elsewhere and run the batch file with the starting num=26.
    Quote Quote  
  17. 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
    Quote Quote  
  18. Member
    Join Date
    Jul 2009
    Location
    United States
    Search Comp PM
    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.
    Quote Quote  
  19. Originally Posted by jagabo View Post
    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'm supposed to edit the bat file and replace the arguments (%X) for first, last, OutNum and the image extension. Right?
    I did that but the prompt says it can't find the specified files.
    Quote Quote  
  20. Originally Posted by naoto89 View Post
    I'm supposed to edit the bat file and replace the arguments (%X) for first, last, OutNum and the image extension. Right?
    No, you specify them on the command line. Example command lines are given in the remarks.
    Quote Quote  
  21. Originally Posted by jagabo View Post
    Originally Posted by naoto89 View Post
    I'm supposed to edit the bat file and replace the arguments (%X) for first, last, OutNum and the image extension. Right?
    No, you specify them on the command line. Example command lines are given in the remarks.
    I understand that should be put inside "do ( )" but in which of all those lines should I edit and put that similar code?
    Quote Quote  
  22. You don't edit the file at all. You type the commands in a command line window.
    Quote Quote  
  23. 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
    Quote Quote  
  24. Member
    Join Date
    Aug 2020
    Location
    Randallstown, MD
    Search Comp PM
    (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
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!