首页 > 解决方案 > Windows 删除所有供应商和 node_modules

问题描述

我在删除我的 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。

标签: powershellcmdwindows-10git-bash

解决方案


您可以在 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

我听说使用-Recurseand可能会出现性能问题-Include。我自己从未见过它,但如果您有一个大型目录结构并看到性能下降,请记住这一点。


推荐阅读