Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Rename multiple files from another folder  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

zbiebu

    Topic Starter


    Starter

    Rename multiple files from another folder
    « on: February 02, 2010, 08:24:01 AM »
    Hi,

    I would like to be able to change the file extension on several files at once, but the batch file needs to be in another folder to those files being changed.

    For example the files are contained in C:\Aa\temp, and the batch file needs to be in the root of C. The process will be to change the extension from txt to xml, move the files and then change them back to txt. The movement of the files is a separate process and need not be incorporated into a batch file.
    Anyone any ideas?

    Thanks

     ???

    gpl



      Apprentice
    • Thanked: 27
      Re: Rename multiple files from another folder
      « Reply #1 on: February 02, 2010, 08:38:18 AM »
      yes - 2 ways
      1]
      Code: [Select]
      cd /d C:\Aa\temp
      c:\batchfilename
      2]
      rewrite your batchfile to accept the name of a directory as a parameter and reference your files using the parameter as the path

      1] is simplest and it will work on any drive / directory

      zbiebu

        Topic Starter


        Starter

        Re: Rename multiple files from another folder
        « Reply #2 on: February 02, 2010, 09:57:48 AM »
        Hi,

        Thanks for your reply. sorry I'm not sure what you mean about creating a batch file to accept parameters. could you please explain a little further.

        Many thanks


        gpl



          Apprentice
        • Thanked: 27
          Re: Rename multiple files from another folder
          « Reply #3 on: February 02, 2010, 10:04:57 AM »
          It would be a lot easier with an example ... could you paste the contents of your batch file and I will show you how to amend it

          zbiebu

            Topic Starter


            Starter

            Re: Rename multiple files from another folder
            « Reply #4 on: February 02, 2010, 10:25:40 AM »
            Hi,

            Here it is

            @echo off
            RENAME C:\Aa\Test\ *.xml *.sst

            Thanks

            gpl



              Apprentice
            • Thanked: 27
              Re: Rename multiple files from another folder
              « Reply #5 on: February 02, 2010, 11:10:52 AM »
              ok then,using your batch, Ill colour code my changes

              @echo off
              REM %1 is a special variable, the first parameter passed
              REM test if any parameter was supplied

              If [%1]==[] Goto Error
              REM OK, the ~ char in %~1 means strip off the quotes
              RENAME "%~1\*.xml" *.sst
              GoTo :EOF
              REM no param, show error message
              :Error
              Echo Supply a directory name on the command line, eg
              REM %0 is the name of the batchfile as entered on the command line
              Echo %0 "My Folder"

              zbiebu

                Topic Starter


                Starter

                Re: Rename multiple files from another folder
                « Reply #6 on: February 03, 2010, 04:26:17 AM »
                Hi,

                Thanks for your reply. I'll give it a try. How would I call the batch and put the variable at the command line?

                Thanks

                gpl



                  Apprentice
                • Thanked: 27
                  Re: Rename multiple files from another folder
                  « Reply #7 on: February 03, 2010, 04:34:10 AM »
                  Good luck with it
                  Suppose we called the batchfile RenameXML.bat

                  then the commandline would be

                  RenameXML C:\Aa\Test

                  assuming you were in the root, if not then

                  C:\RenameXML C:\Aa\Test