Script to automate copy files with a pattern over network












0















I am trying to automate some tasks... I have to do some development work on one machine and other parts on another machine, with communication through a network share.



I would like to copy certain files, not the entire directories - which may contain lots of additional build items, some large.



Something like



set source="C:UsersmeDocumentssourcefolder"
set dest="\SHAREFOLDERmedestfolder"
xcopy %source%+"*.cpp" %dest%


How can I do a command like this ? copy all files with a given pattern (like *.cpp) from source to destination ?



Also - can that be done recursively - for all the folders inside source ?



Edit:



Trying



xcopy "C:UsersmeDocumentssourcefolder*.cpp" "\SHAREFOLDERmedestfolder"


(first try did not work because I did not know I should make a bat file. Thank you Saggio.)



Still... for best results, for a complex directory structure I would like to be able to use variables and perhaps copy recursively - there are many directories I have to copy over.



Also, the patterns I want to copy are something like "all files with extension .cpp, except those that start with moc_" or ""all files with extension .h, except those that start with ui_"



I could copy then delete the ones hat I don't want I guess... But is there a better way ?










share|improve this question

























  • couldn't you just do xcopy %source%*.cpp %dest%?

    – Saggio
    Nov 4 '14 at 22:22











  • I am trying... so far I get an error about compatibility... and when trying to use the "Compatibility" tab to run, no error but also nothing happens.

    – Thalia
    Nov 4 '14 at 22:25











  • What errors are you seeing specifically?

    – Richard Turner
    Nov 4 '14 at 22:25






  • 2





    why are you creating an executable file? It looks like move.exe is x86 and you're in an x64 environment. Since it's working running it straight from the cmd line, perhaps just create a a *.bat file script instead of a full fledged executable?

    – Saggio
    Nov 4 '14 at 22:31






  • 1





    @Saggio thank you, now I feel ridiculous... I did not know how to create a windows script...

    – Thalia
    Nov 4 '14 at 22:33
















0















I am trying to automate some tasks... I have to do some development work on one machine and other parts on another machine, with communication through a network share.



I would like to copy certain files, not the entire directories - which may contain lots of additional build items, some large.



Something like



set source="C:UsersmeDocumentssourcefolder"
set dest="\SHAREFOLDERmedestfolder"
xcopy %source%+"*.cpp" %dest%


How can I do a command like this ? copy all files with a given pattern (like *.cpp) from source to destination ?



Also - can that be done recursively - for all the folders inside source ?



Edit:



Trying



xcopy "C:UsersmeDocumentssourcefolder*.cpp" "\SHAREFOLDERmedestfolder"


(first try did not work because I did not know I should make a bat file. Thank you Saggio.)



Still... for best results, for a complex directory structure I would like to be able to use variables and perhaps copy recursively - there are many directories I have to copy over.



Also, the patterns I want to copy are something like "all files with extension .cpp, except those that start with moc_" or ""all files with extension .h, except those that start with ui_"



I could copy then delete the ones hat I don't want I guess... But is there a better way ?










share|improve this question

























  • couldn't you just do xcopy %source%*.cpp %dest%?

    – Saggio
    Nov 4 '14 at 22:22











  • I am trying... so far I get an error about compatibility... and when trying to use the "Compatibility" tab to run, no error but also nothing happens.

    – Thalia
    Nov 4 '14 at 22:25











  • What errors are you seeing specifically?

    – Richard Turner
    Nov 4 '14 at 22:25






  • 2





    why are you creating an executable file? It looks like move.exe is x86 and you're in an x64 environment. Since it's working running it straight from the cmd line, perhaps just create a a *.bat file script instead of a full fledged executable?

    – Saggio
    Nov 4 '14 at 22:31






  • 1





    @Saggio thank you, now I feel ridiculous... I did not know how to create a windows script...

    – Thalia
    Nov 4 '14 at 22:33














0












0








0


1






I am trying to automate some tasks... I have to do some development work on one machine and other parts on another machine, with communication through a network share.



I would like to copy certain files, not the entire directories - which may contain lots of additional build items, some large.



Something like



set source="C:UsersmeDocumentssourcefolder"
set dest="\SHAREFOLDERmedestfolder"
xcopy %source%+"*.cpp" %dest%


How can I do a command like this ? copy all files with a given pattern (like *.cpp) from source to destination ?



Also - can that be done recursively - for all the folders inside source ?



Edit:



Trying



xcopy "C:UsersmeDocumentssourcefolder*.cpp" "\SHAREFOLDERmedestfolder"


(first try did not work because I did not know I should make a bat file. Thank you Saggio.)



Still... for best results, for a complex directory structure I would like to be able to use variables and perhaps copy recursively - there are many directories I have to copy over.



Also, the patterns I want to copy are something like "all files with extension .cpp, except those that start with moc_" or ""all files with extension .h, except those that start with ui_"



I could copy then delete the ones hat I don't want I guess... But is there a better way ?










share|improve this question
















I am trying to automate some tasks... I have to do some development work on one machine and other parts on another machine, with communication through a network share.



I would like to copy certain files, not the entire directories - which may contain lots of additional build items, some large.



Something like



set source="C:UsersmeDocumentssourcefolder"
set dest="\SHAREFOLDERmedestfolder"
xcopy %source%+"*.cpp" %dest%


How can I do a command like this ? copy all files with a given pattern (like *.cpp) from source to destination ?



Also - can that be done recursively - for all the folders inside source ?



Edit:



Trying



xcopy "C:UsersmeDocumentssourcefolder*.cpp" "\SHAREFOLDERmedestfolder"


(first try did not work because I did not know I should make a bat file. Thank you Saggio.)



Still... for best results, for a complex directory structure I would like to be able to use variables and perhaps copy recursively - there are many directories I have to copy over.



Also, the patterns I want to copy are something like "all files with extension .cpp, except those that start with moc_" or ""all files with extension .h, except those that start with ui_"



I could copy then delete the ones hat I don't want I guess... But is there a better way ?







windows shell network-shares file-transfer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 4 '14 at 22:42







Thalia

















asked Nov 4 '14 at 22:14









ThaliaThalia

29511024




29511024













  • couldn't you just do xcopy %source%*.cpp %dest%?

    – Saggio
    Nov 4 '14 at 22:22











  • I am trying... so far I get an error about compatibility... and when trying to use the "Compatibility" tab to run, no error but also nothing happens.

    – Thalia
    Nov 4 '14 at 22:25











  • What errors are you seeing specifically?

    – Richard Turner
    Nov 4 '14 at 22:25






  • 2





    why are you creating an executable file? It looks like move.exe is x86 and you're in an x64 environment. Since it's working running it straight from the cmd line, perhaps just create a a *.bat file script instead of a full fledged executable?

    – Saggio
    Nov 4 '14 at 22:31






  • 1





    @Saggio thank you, now I feel ridiculous... I did not know how to create a windows script...

    – Thalia
    Nov 4 '14 at 22:33



















  • couldn't you just do xcopy %source%*.cpp %dest%?

    – Saggio
    Nov 4 '14 at 22:22











  • I am trying... so far I get an error about compatibility... and when trying to use the "Compatibility" tab to run, no error but also nothing happens.

    – Thalia
    Nov 4 '14 at 22:25











  • What errors are you seeing specifically?

    – Richard Turner
    Nov 4 '14 at 22:25






  • 2





    why are you creating an executable file? It looks like move.exe is x86 and you're in an x64 environment. Since it's working running it straight from the cmd line, perhaps just create a a *.bat file script instead of a full fledged executable?

    – Saggio
    Nov 4 '14 at 22:31






  • 1





    @Saggio thank you, now I feel ridiculous... I did not know how to create a windows script...

    – Thalia
    Nov 4 '14 at 22:33

















couldn't you just do xcopy %source%*.cpp %dest%?

– Saggio
Nov 4 '14 at 22:22





couldn't you just do xcopy %source%*.cpp %dest%?

– Saggio
Nov 4 '14 at 22:22













I am trying... so far I get an error about compatibility... and when trying to use the "Compatibility" tab to run, no error but also nothing happens.

– Thalia
Nov 4 '14 at 22:25





I am trying... so far I get an error about compatibility... and when trying to use the "Compatibility" tab to run, no error but also nothing happens.

– Thalia
Nov 4 '14 at 22:25













What errors are you seeing specifically?

– Richard Turner
Nov 4 '14 at 22:25





What errors are you seeing specifically?

– Richard Turner
Nov 4 '14 at 22:25




2




2





why are you creating an executable file? It looks like move.exe is x86 and you're in an x64 environment. Since it's working running it straight from the cmd line, perhaps just create a a *.bat file script instead of a full fledged executable?

– Saggio
Nov 4 '14 at 22:31





why are you creating an executable file? It looks like move.exe is x86 and you're in an x64 environment. Since it's working running it straight from the cmd line, perhaps just create a a *.bat file script instead of a full fledged executable?

– Saggio
Nov 4 '14 at 22:31




1




1





@Saggio thank you, now I feel ridiculous... I did not know how to create a windows script...

– Thalia
Nov 4 '14 at 22:33





@Saggio thank you, now I feel ridiculous... I did not know how to create a windows script...

– Thalia
Nov 4 '14 at 22:33










1 Answer
1






active

oldest

votes


















0














Did not list you OS and enviroment
If you can use robocopy
it has all the tools you need to do this depending on your details :



robocopy %source% %dest% *.cpp /s



will copy all cpp files from the source to dest



it includes many other options for automating this task depending on exactly what you want. just do a robocopy /? and it will list them. For example, you can do a test robocopy that only shows what it would have done if it had been for real.
/L :: List only - don't copy, timestamp or delete any files.






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%2f835969%2fscript-to-automate-copy-files-with-a-pattern-over-network%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














    Did not list you OS and enviroment
    If you can use robocopy
    it has all the tools you need to do this depending on your details :



    robocopy %source% %dest% *.cpp /s



    will copy all cpp files from the source to dest



    it includes many other options for automating this task depending on exactly what you want. just do a robocopy /? and it will list them. For example, you can do a test robocopy that only shows what it would have done if it had been for real.
    /L :: List only - don't copy, timestamp or delete any files.






    share|improve this answer




























      0














      Did not list you OS and enviroment
      If you can use robocopy
      it has all the tools you need to do this depending on your details :



      robocopy %source% %dest% *.cpp /s



      will copy all cpp files from the source to dest



      it includes many other options for automating this task depending on exactly what you want. just do a robocopy /? and it will list them. For example, you can do a test robocopy that only shows what it would have done if it had been for real.
      /L :: List only - don't copy, timestamp or delete any files.






      share|improve this answer


























        0












        0








        0







        Did not list you OS and enviroment
        If you can use robocopy
        it has all the tools you need to do this depending on your details :



        robocopy %source% %dest% *.cpp /s



        will copy all cpp files from the source to dest



        it includes many other options for automating this task depending on exactly what you want. just do a robocopy /? and it will list them. For example, you can do a test robocopy that only shows what it would have done if it had been for real.
        /L :: List only - don't copy, timestamp or delete any files.






        share|improve this answer













        Did not list you OS and enviroment
        If you can use robocopy
        it has all the tools you need to do this depending on your details :



        robocopy %source% %dest% *.cpp /s



        will copy all cpp files from the source to dest



        it includes many other options for automating this task depending on exactly what you want. just do a robocopy /? and it will list them. For example, you can do a test robocopy that only shows what it would have done if it had been for real.
        /L :: List only - don't copy, timestamp or delete any files.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 24 '16 at 17:21









        bvaughnbvaughn

        73349




        73349






























            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%2f835969%2fscript-to-automate-copy-files-with-a-pattern-over-network%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 make a Squid Proxy server?

            Is this a new Fibonacci Identity?

            Touch on Surface Book