Announcement

Collapse
No announcement yet.

Batch Rename via Command Line

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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, 04:47 PM.

    #2
    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.

    Comment


      #3
      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.
      Before you post ... Edit your profile • IrfanView 4.62 • Windows 10 Home 19045.2486

      Irfan PaintIrfan View HelpIrfanPaint HelpRiot.dllMore SkinsFastStone CaptureUploads

      Comment


        #4
        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.

        Comment


          #5
          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.

          Comment


            #6
            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, 10:36 PM.

            Comment


              #7
              Hi Skippybox,

              Then use the move command.

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

              Comment


                #8
                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.

                Comment


                  #9
                  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!

                  Comment


                    #10
                    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

                    Comment


                      #11
                      Nils,

                      You didn't have to go and do all the work for me! I appreciate the wonderful script, but I thought you were going to just show me how to get started. I'm afraid I am not familiar with such elaborate batch files, so I may have trouble figuring out what you have done. Thanks again!

                      Comment


                        #12
                        Hi,

                        don't worry..

                        Comment

                        Working...
                        X