Output filenames with for loop in a batch file












0















I want to rename files with a batch command and capture the original and renamed files in a list in order to provide a cross reference (doing a DIR /OS >file both before and after the batch file is not rigourous enough).



The file below carries out the renaming fine, but my understanding is not good enough to get the output bit working (if it even is possible). Also, the output in the example below is different depending on whether output is to file or screen.



I want to be able to understand more of this:



@echo off
set /a c=%1
setLocal ENABLEDELAYEDEXPANSION
For %%G in (*.tif) do (
echo %%G >infile.txt
ren %%G abc.!c!.tif
set /a c=c+1
echo %%G >outfile.txt
)
endlocal









share|improve this question





























    0















    I want to rename files with a batch command and capture the original and renamed files in a list in order to provide a cross reference (doing a DIR /OS >file both before and after the batch file is not rigourous enough).



    The file below carries out the renaming fine, but my understanding is not good enough to get the output bit working (if it even is possible). Also, the output in the example below is different depending on whether output is to file or screen.



    I want to be able to understand more of this:



    @echo off
    set /a c=%1
    setLocal ENABLEDELAYEDEXPANSION
    For %%G in (*.tif) do (
    echo %%G >infile.txt
    ren %%G abc.!c!.tif
    set /a c=c+1
    echo %%G >outfile.txt
    )
    endlocal









    share|improve this question



























      0












      0








      0








      I want to rename files with a batch command and capture the original and renamed files in a list in order to provide a cross reference (doing a DIR /OS >file both before and after the batch file is not rigourous enough).



      The file below carries out the renaming fine, but my understanding is not good enough to get the output bit working (if it even is possible). Also, the output in the example below is different depending on whether output is to file or screen.



      I want to be able to understand more of this:



      @echo off
      set /a c=%1
      setLocal ENABLEDELAYEDEXPANSION
      For %%G in (*.tif) do (
      echo %%G >infile.txt
      ren %%G abc.!c!.tif
      set /a c=c+1
      echo %%G >outfile.txt
      )
      endlocal









      share|improve this question
















      I want to rename files with a batch command and capture the original and renamed files in a list in order to provide a cross reference (doing a DIR /OS >file both before and after the batch file is not rigourous enough).



      The file below carries out the renaming fine, but my understanding is not good enough to get the output bit working (if it even is possible). Also, the output in the example below is different depending on whether output is to file or screen.



      I want to be able to understand more of this:



      @echo off
      set /a c=%1
      setLocal ENABLEDELAYEDEXPANSION
      For %%G in (*.tif) do (
      echo %%G >infile.txt
      ren %%G abc.!c!.tif
      set /a c=c+1
      echo %%G >outfile.txt
      )
      endlocal






      windows cmd.exe






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 2 '14 at 13:53









      Der Hochstapler

      68.3k50230286




      68.3k50230286










      asked Apr 25 '12 at 14:00









      user130218user130218

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          After sleeping over it I found the answer to the problem. I only have to write the name of the file that is about to be renamed as I 'know' what I am about to call it! Obvious in the end.



          set /a c=%1
          set param=%2
          setLocal ENABLEDELAYEDEXPANSION
          FOR %%i in (*.tif) do (
          echo %%i >>in.txt
          ren %%i %param%!c!.tif
          echo %param%!c!.tif >>out.txt
          set /a c=c+1
          )
          endlocal


          All I need to do now is put in a test to stop it renaming again the first file it renamed (can happen depending on the number being used in var 'c' and the original file names).






          share|improve this answer


























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f416715%2foutput-filenames-with-for-loop-in-a-batch-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            After sleeping over it I found the answer to the problem. I only have to write the name of the file that is about to be renamed as I 'know' what I am about to call it! Obvious in the end.



            set /a c=%1
            set param=%2
            setLocal ENABLEDELAYEDEXPANSION
            FOR %%i in (*.tif) do (
            echo %%i >>in.txt
            ren %%i %param%!c!.tif
            echo %param%!c!.tif >>out.txt
            set /a c=c+1
            )
            endlocal


            All I need to do now is put in a test to stop it renaming again the first file it renamed (can happen depending on the number being used in var 'c' and the original file names).






            share|improve this answer






























              0














              After sleeping over it I found the answer to the problem. I only have to write the name of the file that is about to be renamed as I 'know' what I am about to call it! Obvious in the end.



              set /a c=%1
              set param=%2
              setLocal ENABLEDELAYEDEXPANSION
              FOR %%i in (*.tif) do (
              echo %%i >>in.txt
              ren %%i %param%!c!.tif
              echo %param%!c!.tif >>out.txt
              set /a c=c+1
              )
              endlocal


              All I need to do now is put in a test to stop it renaming again the first file it renamed (can happen depending on the number being used in var 'c' and the original file names).






              share|improve this answer




























                0












                0








                0







                After sleeping over it I found the answer to the problem. I only have to write the name of the file that is about to be renamed as I 'know' what I am about to call it! Obvious in the end.



                set /a c=%1
                set param=%2
                setLocal ENABLEDELAYEDEXPANSION
                FOR %%i in (*.tif) do (
                echo %%i >>in.txt
                ren %%i %param%!c!.tif
                echo %param%!c!.tif >>out.txt
                set /a c=c+1
                )
                endlocal


                All I need to do now is put in a test to stop it renaming again the first file it renamed (can happen depending on the number being used in var 'c' and the original file names).






                share|improve this answer















                After sleeping over it I found the answer to the problem. I only have to write the name of the file that is about to be renamed as I 'know' what I am about to call it! Obvious in the end.



                set /a c=%1
                set param=%2
                setLocal ENABLEDELAYEDEXPANSION
                FOR %%i in (*.tif) do (
                echo %%i >>in.txt
                ren %%i %param%!c!.tif
                echo %param%!c!.tif >>out.txt
                set /a c=c+1
                )
                endlocal


                All I need to do now is put in a test to stop it renaming again the first file it renamed (can happen depending on the number being used in var 'c' and the original file names).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 26 '12 at 11:19









                slhck

                163k47449473




                163k47449473










                answered Apr 26 '12 at 10:22









                user130218user130218

                11




                11






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f416715%2foutput-filenames-with-for-loop-in-a-batch-file%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Probability when a professor distributes a quiz and homework assignment to a class of n students.

                    Aardman Animations

                    Are they similar matrix