Remove Stubborn Node_modules

Source: Internet
Author: User
Tags robocopy

Useful to gulp,webpack at work, using some module packages that rely on node, they generate a node_modules folder in the directory. Once I tried to erase it. Rebuild the module package when it is not possible to find it is not likely, endless report a mistake: the path is too long (too deep), can not be deleted, using the command line rd , del the attempt is not valid (this problem win10 system does not appear, the small partners hurriedly update the system bar).

At first I could only re-enable the new project through a different folder, and found more and more zombie files, a few twists and turns, and finally found a solution. The steps are as follows:

    1. Create a new blank directory, such as D:\Study\emptyDir ;
    2. Administrator to open the command-line window;
    3. Inputrobocopy D:\Study\emptyDir D:\Study\node_modules /purge

Here the main use of the Robocopy command, which is a directory copy command, configuration parameters can achieve the effect of deleting files,

Command syntax: ROBOCOPY source destination [file [file] ...] [Options]

    1. Source: Origin directory (drive: \ path or \ \ server \ share \ Path)
    2. Destination: Destination directory (drive: \ path or \ \ server \ share \ Path)
    3. [file [file] ...] : File to be copied (name/wildcard: "* *" by default)
    4. When the options parameter is set to/purse, you can delete target files/directories that no longer exist in the source.

here, an empty file to make the source file, equivalent to all the files in the target file is to be deleted, so as to resolve the deletion problem .

Although the problem of file deletion is resolved, but the total feeling is missing something, that is, feel the operation has this frequency, when I think of the current command line can be packaged into a file quickly executed, then thought. bat batch file.

So Baidu brain complements the next batch processing file production method, generated the following batch file, the code is roughly as follows:

@echo offColor 0bModeCon cols=80 lines=25Echo -----------------------------------------------------------------EchoStubborn file deletionEcho -----------------------------------------------------------------Echo ******************************************************************EchoTips:EchoInput: Delete node_modules in current directoryEchoEnter other: The folder with the corresponding file name will be deletedEcho ******************************************************************Set/P delefile=Please enter the file you want to delete:if%delefile% = = * (GotoDelenodemodules)Else(GotoDeleuserfile):d elenodemodulesMDdeleemptyfilerobocopy deleemptyfile node_modules/PurgeRdNode_modulesRdDeleemptyfileExit:d EleuserfileMDdeleemptyfilerobocopy deleemptyfile%delefile%/PurgeRd%delefile%RdDeleemptyfileExit

I would like to implement when prompted " Please enter the file you want to delete" Direct carriage return should be directly deleted node_modules folder, but has not been implemented, temporarily do enter an asterisk is to delete the Node_modules folder , enter the other to delete the corresponding folder name. Batch folder download, you can download to the local and put the. bat file in the same directory to delete the folder, double-click to run the prompt input to batch run the above command implementation to delete files.

Before using this command, it is best to delete the first, only the remaining files can not be deleted by this method to delete, such as the direct use of this command to delete the wait time is a little long, deleted when the situation is roughly as follows:

Personal capacity is limited, if you can implement the direct return of the folder without entering the file can be directly deleted Node_modules folder Welcome message sharing, thank you, learn together, progress together!

Remove Stubborn Node_modules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.