[英]How to delete only the sub-folders and sub-folder contents but not individual files from the root of a folder using powershell
A given folder "AppInstall" contains multiple unknown installation packages but the logs for those packages exist in the root of "AppInstall".给定文件夹“AppInstall”包含多个未知安装包,但这些包的日志存在于“AppInstall”的根目录中。 I want to delete the folders and contents of "packages" without deleting the logs in the root of "AppInstall".
我想删除“包”的文件夹和内容,而不删除“AppInstall”根目录中的日志。
Example:例子:
Before removal code删除前代码
C:\AppInstall\Package1\AnotherFolder\something.txt
C:\AppInstall\Package1\a.txt
C:\AppInstall\Package1\b.txt
C:\AppInstall\Package1\c.txt
C:\AppInstall\Package2\a.txt
C:\AppInstall\Package2\b.txt
C:\AppInstall\Package1.log
C:\AppInstall\Package2.log
After removal code删除代码后
C:\AppInstall\Package1.log
C:\AppInstall\Package2.log
您可以使用-Directory
开关 (v3+) 检索目录下的文件夹,然后您可以使用-Recurse
将其通过管道传输到Remove-Item
以删除所有内容,并使用-Force
抑制提示:
Get-ChildItem -Path C:\AppInstall -Directory | Remove-Item -Recurse -Force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.