I want to backup my work folder which is mainly contained within a folder structure such as:

    - project 1
        - assets
        - node_modules
    - project 1
        - assets
        - node_modules
    - project 1
        - assets
        - node_modules

I need to copy all of the projects but exclude the node_modules folder within each project. Is there an easy way to do this in bulk? As I have large quantities of projects to go through.

Running on Windows 8.1


I need to copy all of the projects but exclude the node_modules folder

You can use xcopy together with the exclude option:

xcopy www backup /exclude:except.txt
  • except.txt contains the list of files of directories to be excluded.




  • The files can each contain one or more full or partial pathnames to be excluded.
  • When any of these match any part of the absolute path of a SOURCE file, then that file will be excluded.
  • For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively.

Source xcopy - Copy files and/or directory trees to another folder.

Further reading

|improve this answer|||||
  • Awesome, thank you I will give this a go. I also found this: robocopy SOURCE DESTINATION /mir /xd FOLDER_TO_EXCLUDE — I Assume it could work too? – Doidgey Jul 15 '15 at 9:02
  • Quite likely. I don't know robocopy though :/ Please don't forget to accept my answer ;) – DavidPostill Jul 15 '15 at 9:02
  • Give robocopy a try - it was designed to support the same command options as xcopy but features a lot of improvements - long path support, buffering, unicode, it preserves timestamps etc. etc. Robocopy is part of Windows since Vista, installable on XP. – user1016274 Jul 15 '15 at 10:58
  • This command did not copy any subfolder from my source, only files within that folder. – Qwerty Aug 7 '18 at 12:43
  • @DavidPostill Do I seriously have to put the directories I want to exclude in a text file and then reference that text file in the command? Can't I just tell it directly which directories I want to exclude? I guess robocopy is better. – Shayan Sep 27 '19 at 12:57

Thanks to @DavidPostill for his answer. It worked a treat. I did however also managed to get robocopy working. For those whom it might help, the command was:

robocopy SOURCE DEST /mir /xd node_modules

Source being the folder to copy, and dest being the destination. And right at the end I have node_modules as the folder I want to exclude.

|improve this answer|||||
  • 2
    Good ol' robocopy /mir. Very powerful switch that can do a lot of good, but just be aware of what that switch does before you go using it. It will sync two dirs, including deleting items if they don't exist in the source dir. – Adam Plocher Feb 15 '17 at 9:32
  • Thank you so much! This works very well for syncing my Documents folder with Dropbox, but excluding the node_modules folders since they take up so much space – Ben Gubler Jan 26 '19 at 23:14
  • 1
    @AdamPlocher Your comment saved me from data loss. I've been using robocopy as a substitute for moving folders, didn't occur to me it would delete files from the target folder. Thankfully I was able to recover a backup from 4 days ago, so thank you. – Hay Apr 20 '19 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.