Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Batch Rename via Command Line

  1. #1
    Professional User Skippybox's Avatar
    Join Date
    Jul 2008
    Location
    Detroit, MI USA
    Posts
    2,030
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Home SP2
    CPU Cores
    1

    Question Batch Rename via Command Line

    How does someone do a batch rename via the command line without altering the file, except its name? That is, how do you do the rename without doing a conversion? Is it possible?
    Last edited by Skippybox; 09.09.2008 at 03:47 PM.

  2. #2
    Professional User Skippybox's Avatar
    Join Date
    Jul 2008
    Location
    Detroit, MI USA
    Posts
    2,030
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Home SP2
    CPU Cores
    1

    Default

    I would like to do the batch rename without the program resaving the file using the settings for the file type. For instance, I don't want a jpg to be converted to a jpg just because I change the name in the command line.

  3. #3
    Moderator Enterprise User Bhikkhu Pesala's Avatar
    Join Date
    May 2007
    Location
    East London
    Posts
    6,072
    OS
    64-bit Win 10
    CPU Cores
    1

    Default

    I don't see any reason why renaming should be converting your files.

    See Batch Renaming

    There are three options on the dialogue: Convert, Rename, or Both.

  4. #4
    Professional User Skippybox's Avatar
    Join Date
    Jul 2008
    Location
    Detroit, MI USA
    Posts
    2,030
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Home SP2
    CPU Cores
    1

    Default

    Quote Originally Posted by Bhikkhu Pesala View Post
    I don't see any reason why renaming should be converting your files.

    There are three options on the dialogue: Convert, Rename, or Both.
    My question specified that I am trying to rename via the command line, not the Batch Conversion/Rename dialog.

  5. #5
    Moderator Laurent's Avatar
    Join Date
    May 2007
    Location
    Brussels, Belgium
    Posts
    882
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Pro SP3
    CPU Cores
    2

    Default

    Hi Skippybox,

    Why do you want to use IrfanView ? The DOS "rename" command could do that.

    Laurent
    Before you post ... fill in your OS and IV version in your profile.

  6. #6
    Professional User Skippybox's Avatar
    Join Date
    Jul 2008
    Location
    Detroit, MI USA
    Posts
    2,030
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Home SP2
    CPU Cores
    1

    Default

    Quote Originally Posted by Laurent View Post
    Why do you want to use IrfanView ? The DOS "rename" command could do that.
    Hi Laurent,

    The DOS 'rename' command does not allow you to specify a new path for the file. Is the Batch dialog the only way in IrfanView? I would like to do it without an interface, so I could turn it into a shortcut. Is a batch file better. Any ideas?
    Last edited by Skippybox; 09.09.2008 at 09:36 PM.

  7. #7
    Moderator Laurent's Avatar
    Join Date
    May 2007
    Location
    Brussels, Belgium
    Posts
    882
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Pro SP3
    CPU Cores
    2

    Default

    Hi Skippybox,

    Then use the move command.

    Laurent
    Before you post ... fill in your OS and IV version in your profile.

  8. #8
    Moderator
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    855
    Version
    IrfanView 4.51
    OS
    64-bit Win 10
    CPU Cores
    8

    Default

    Hi Skippybox,

    this is possible, with a few restrictions:
    if you have german umlauts or special characters like "&" or "+" in the filename, than windows can deal with them, a DOS script not (ok, a DOS script can work with the german umlaut but you can not convert it easy from the Windows character set to the DOS character set).

    What do you exactly need? A script which you can put in the send to folder and you want to send an folder to this script. The script shall move, copy or rename the files to another given or asked name?

    Maybe I can help you.

    Regards, Nils.

  9. #9
    Professional User Skippybox's Avatar
    Join Date
    Jul 2008
    Location
    Detroit, MI USA
    Posts
    2,030
    Version
    IrfanView 4.25
    OS
    32-bit Win XP Home SP2
    CPU Cores
    1

    Default

    Quote Originally Posted by derniwi View Post
    What do you exactly need? A script which you can put in the send to folder and you want to send an folder to this script. The script shall move, copy or rename the files to another given or asked name?
    Hi Nils,

    I probably should use a renamer program, but I would like to experiment with scripting. I was basically looking for a quick way using a shortcut to re-pad a folder of files to make sorting easier. I would like a script similar to what you described. I know you are quite talented at batch files. Perhaps you could give me some pointers or share your ideas with me? I would love to learn!

  10. #10
    Moderator
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    855
    Version
    IrfanView 4.51
    OS
    64-bit Win 10
    CPU Cores
    8

    Default

    Hi Skippy,

    so take a look at this script. But use it with care! I have done just a few little tests...
    Code:
    @echo off
    rem ask for values?
    set askfor=y
    
    rem set default values
    set defdestpath=D:\renamed
    set defpattern=*.jpg
    set defcopymove=c
    set defprefix=My_picture_
    set defpostfix=_fun
    set /a defstartnum=1
    
    rem the source path is passed from the send to function
    set sourcepath=%~1
    
    rem allow the output path to be dragged and dropped to the dos box
    if "%askfor%" == "y" set /p destpath=Rename to path [%defdestpath%]: 
    if "%destpath%" == "" set destpath=%defdestpath%
    
    rem ask for file pattern
    if "%askfor%" == "y" set /p pattern=File pattern [%defpattern%]: 
    if "%pattern%" == "" set pattern=%defpattern%
    
    rem ask for copying or moving
    if "%askfor%" == "y" set /p copymove=Copy or Move [%defcopymove%]: 
    if "%copymove%" == "" set copymove=%defcopymove%
    
    rem check if the files should be copied or moved
    set copymove=%copymove:~0,1%
    if /i "%copymove%" == "m" set copymove=move
    if /i "%copymove%" neq "move" set copymove=copy
    
    rem ask for file name prefix
    if "%askfor%" == "y" set /p prefix=File prefix [%defprefix%]: 
    if "%prefix%" == "" set prefix=%defprefix%
    
    rem ask for file name postfix
    if "%askfor%" == "y" set /p postfix=File postfix [%defpostfix%]: 
    if "%postfix%" == "" set postfix=%defpostfix%
    
    rem ask for starting number
    if "%askfor%" == "y" set /p startnum=Starting number [%defstartnum%]: 
    if "%startnum%" == "" set startnum=%defstartnum%
    set /a startnum=%startnum%
    
    
    rem check for files
    if not exist "%sourcepath%\%pattern%" goto NoFiles
    
    rem check if outpath contains a drive letter
    set drive=%destpath:~0,2%
    set drive=%drive:~1,1%
    if "%drive%" neq ":" set destpath=%sourcepath%\%destpath%
    
    rem check if the output path exist
    if not exist "%destpath%\." md "%destpath%"
    
    
    for /f "delims=" %%a in ('dir /b /a-d /on "%sourcepath%\%pattern%"') do call :rename "%sourcepath%\%%a"
    goto end
    
    rem Move the files
    :rename
    set suffix=%~X1
    set number=0000%startnum%
    set number=%number:~-4%
    
    set filename=%prefix%%number%%postfix%%suffix%
    %copymove% %1 "%destpath%\%filename%"
    
    set /a startnum=startnum + 1
    goto :eof
    
    rem Write some text if no files are found
    :NoFiles
    echo Sorry, but I can't find files matching "%pattern%" in the
    echo directory "%sourcepath%".
    goto end
    
    :end
    pause

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •