【问题标题】:Windows delete all vendors and node_modulesWindows 删除所有供应商和 node_modules
【发布时间】:2020-11-15 05:37:30
【问题描述】:

我在删除我的 node_modules 和 vendor 文件夹时遇到问题。 我想从电脑上删除它们,我在互联网上找到了各种方法,实际上没有任何帮助。

这实际上确实删除了它们:

FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" del -f "%d"

但它每次都要求我在 cmd 中输入 Y。

有没有办法用 cmd 或 git bash 或 powershell 中的一个命令来完成它?我使用的是 Windows 10。

【问题讨论】:

    标签: powershell cmd windows-10 git-bash


    【解决方案1】:

    您可以在 PowerShell 中执行以下操作:

    Get-ChildItem -Path . -Recurse -Directory -Filter 'node_modules' |
        Remove-Item -Recurse -Confirm:$false -WhatIf
    

    只需删除-WhatIf 参数即可进行实际删除


    如果您想递归地定位多个文件夹,您可以执行以下操作:

    # Example 1: Using variable for readability
    $folders = 'node_modules','vendors'
    Get-ChildItem -Path . -Recurse -Directory -Include $folders |
        Remove-Item -Recurse -Confirm:$false -WhatIf
    
    # Example 2: Not using variable
    Get-ChildItem -Path . -Recurse -Directory -Include 'node_modules','vendors' |
        Remove-Item -Recurse -Confirm:$false -WhatIf
    

    我听说将-Recurse-Include 一起使用可能会出现性能问题。我自己从未见过,但如果您的目录结构很大并且性能下降,请记住这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-02
      • 2018-04-08
      • 2017-05-24
      • 1970-01-01
      • 2015-09-11
      • 2022-09-23
      • 1970-01-01
      • 2014-02-06
      相关资源
      最近更新 更多