Skip to content

Instantly share code, notes, and snippets.

@anuraghazra
Last active January 9, 2024 20:00
Show Gist options
  • Save anuraghazra/95a4150789f6166f75ff566b494c72d9 to your computer and use it in GitHub Desktop.
Save anuraghazra/95a4150789f6166f75ff566b494c72d9 to your computer and use it in GitHub Desktop.
Exclude node_modules folder when copying directory.

Handy Trick To Get Rid Of node_modules

This one is a simple and handy trick when you want to copy your directories without node_modules folder.

Enter this command in your terminal.

robocopy SOURCE DEST /mir /xd node_modules
@julientaq
Copy link

@Itzikil this code copy / paste files, there is no deletion involved.

you must have done something else

@jwallet
Copy link

jwallet commented Apr 24, 2023

@Itzikil

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.

So copy it in a new folder, or use another command that does not sync content.

https://superuser.com/questions/940804/copy-large-number-of-files-but-exclude-certain-sub-folders-on-windows

@don-noonan
Copy link

is it possible that this code delete my files instead of coping??

Yes. The /MIR switch is equivalent to /e /purge which does delete files in certain cases. See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy for full details.

@nitinja
Copy link

nitinja commented Jan 9, 2024

Hi!

For OSX (and i guess other unix)

rsync -av -progress --exclude="node_modules" sourceToCopy destination

Excellent, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment