How to Copy (and increment) Multiple Instances of a File Using Batch File












4















I need to create a batch file that copies a file and increments it upon placing it at the destination. Example.



copy C:TEMPMyDoc.txt E:MyData


Essentially, I need this copy command to copy every time I start it (which it does now just fine). I would like it to increment the file name instead of overwrite it though. If I ran this three times or 100 times (never a certain number) I would like to see on the "MyData" folder:



MyDoc.txt



MyDoc(1).txt



...



Or Copy (1) I'm not really sure what the syntax is for a duplicated file nor do I necessarily care. I just want to ensure that I'm not overwriting the pre-existing file on my jump drive.



The catch is I'm doing this on an Allen Bradley PanelView Plus that is old and running Windows CE. Any help would be greatly appreciated.










share|improve this question



























    4















    I need to create a batch file that copies a file and increments it upon placing it at the destination. Example.



    copy C:TEMPMyDoc.txt E:MyData


    Essentially, I need this copy command to copy every time I start it (which it does now just fine). I would like it to increment the file name instead of overwrite it though. If I ran this three times or 100 times (never a certain number) I would like to see on the "MyData" folder:



    MyDoc.txt



    MyDoc(1).txt



    ...



    Or Copy (1) I'm not really sure what the syntax is for a duplicated file nor do I necessarily care. I just want to ensure that I'm not overwriting the pre-existing file on my jump drive.



    The catch is I'm doing this on an Allen Bradley PanelView Plus that is old and running Windows CE. Any help would be greatly appreciated.










    share|improve this question

























      4












      4








      4








      I need to create a batch file that copies a file and increments it upon placing it at the destination. Example.



      copy C:TEMPMyDoc.txt E:MyData


      Essentially, I need this copy command to copy every time I start it (which it does now just fine). I would like it to increment the file name instead of overwrite it though. If I ran this three times or 100 times (never a certain number) I would like to see on the "MyData" folder:



      MyDoc.txt



      MyDoc(1).txt



      ...



      Or Copy (1) I'm not really sure what the syntax is for a duplicated file nor do I necessarily care. I just want to ensure that I'm not overwriting the pre-existing file on my jump drive.



      The catch is I'm doing this on an Allen Bradley PanelView Plus that is old and running Windows CE. Any help would be greatly appreciated.










      share|improve this question














      I need to create a batch file that copies a file and increments it upon placing it at the destination. Example.



      copy C:TEMPMyDoc.txt E:MyData


      Essentially, I need this copy command to copy every time I start it (which it does now just fine). I would like it to increment the file name instead of overwrite it though. If I ran this three times or 100 times (never a certain number) I would like to see on the "MyData" folder:



      MyDoc.txt



      MyDoc(1).txt



      ...



      Or Copy (1) I'm not really sure what the syntax is for a duplicated file nor do I necessarily care. I just want to ensure that I'm not overwriting the pre-existing file on my jump drive.



      The catch is I'm doing this on an Allen Bradley PanelView Plus that is old and running Windows CE. Any help would be greatly appreciated.







      batch-file copy backup windows-ce increment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 24 '15 at 13:45









      Dustin11h3Dustin11h3

      3215




      3215
























          1 Answer
          1






          active

          oldest

          votes


















          4














          You can try like this :



          @echo off
          set Source=C:TEMPMyDoc.txt
          set Destination=E:MyData
          set Filename=MyDoc
          set a=1

          :loop
          if exist %Destination%%Filename%(%a%).txt set /a a+=1 && goto :loop
          copy %Source% %Destination%%Filename%(%a%).txt
          pause





          share|improve this answer
























          • I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

            – Dustin11h3
            Feb 24 '15 at 20:23








          • 1





            Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

            – Dustin11h3
            Feb 25 '15 at 15:25











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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%2fstackoverflow.com%2fquestions%2f28697436%2fhow-to-copy-and-increment-multiple-instances-of-a-file-using-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









          4














          You can try like this :



          @echo off
          set Source=C:TEMPMyDoc.txt
          set Destination=E:MyData
          set Filename=MyDoc
          set a=1

          :loop
          if exist %Destination%%Filename%(%a%).txt set /a a+=1 && goto :loop
          copy %Source% %Destination%%Filename%(%a%).txt
          pause





          share|improve this answer
























          • I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

            – Dustin11h3
            Feb 24 '15 at 20:23








          • 1





            Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

            – Dustin11h3
            Feb 25 '15 at 15:25
















          4














          You can try like this :



          @echo off
          set Source=C:TEMPMyDoc.txt
          set Destination=E:MyData
          set Filename=MyDoc
          set a=1

          :loop
          if exist %Destination%%Filename%(%a%).txt set /a a+=1 && goto :loop
          copy %Source% %Destination%%Filename%(%a%).txt
          pause





          share|improve this answer
























          • I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

            – Dustin11h3
            Feb 24 '15 at 20:23








          • 1





            Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

            – Dustin11h3
            Feb 25 '15 at 15:25














          4












          4








          4







          You can try like this :



          @echo off
          set Source=C:TEMPMyDoc.txt
          set Destination=E:MyData
          set Filename=MyDoc
          set a=1

          :loop
          if exist %Destination%%Filename%(%a%).txt set /a a+=1 && goto :loop
          copy %Source% %Destination%%Filename%(%a%).txt
          pause





          share|improve this answer













          You can try like this :



          @echo off
          set Source=C:TEMPMyDoc.txt
          set Destination=E:MyData
          set Filename=MyDoc
          set a=1

          :loop
          if exist %Destination%%Filename%(%a%).txt set /a a+=1 && goto :loop
          copy %Source% %Destination%%Filename%(%a%).txt
          pause






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 24 '15 at 18:40









          HackooHackoo

          10.7k31543




          10.7k31543













          • I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

            – Dustin11h3
            Feb 24 '15 at 20:23








          • 1





            Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

            – Dustin11h3
            Feb 25 '15 at 15:25



















          • I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

            – Dustin11h3
            Feb 24 '15 at 20:23








          • 1





            Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

            – Dustin11h3
            Feb 25 '15 at 15:25

















          I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

          – Dustin11h3
          Feb 24 '15 at 20:23







          I'm not having any luck using this code. I keep getting an error that says: "|: incorrect command syntax"

          – Dustin11h3
          Feb 24 '15 at 20:23






          1




          1





          Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

          – Dustin11h3
          Feb 25 '15 at 15:25





          Update: I ran this on my laptop and it worked just fine. For whatever reason, when I run this on the Windows CE machine, it does not like the code. Thanks Hackoo for the help. I have utilized a different method to get done what I needed. The code was simple enough (as I have a slight programming background) I just couldn't figure out how to do that in batch. Thanks again.

          – Dustin11h3
          Feb 25 '15 at 15:25


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f28697436%2fhow-to-copy-and-increment-multiple-instances-of-a-file-using-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

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?