powershell - 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。
解决方案
您可以在 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
and可能会出现性能问题-Include
。我自己从未见过它,但如果您有一个大型目录结构并看到性能下降,请记住这一点。
推荐阅读
- node.js - Npm Start 不运行 node.js,不运行脚本
- java - 使用递归将 NaturalNumbers 除以二
- apache-kafka-connect - How do I upgrade my Debezium plug-in version in Kafka connect?
- python - 将 h5 模型转换为 tensorRT 的 uff 模型时出错
- java - 安装 AdoptOpenJDK 11 并删除旧的 java 8?
- python-3.x - 如何查看 pip(Python 的包安装程序)源代码?
- android - launch_background.xml 不工作重力元素错误
- node.js - req.body 为空且 req.file 未定义,使用 fetch API 上传文件
- c# - WPF .Net Core 3.1 依赖注入/服务参考问题
- performance - 关于数据库事务性能的 Pentaho 表输出