您能帮我...
我有一个具有这种结构的文件夹
MyFloder
|----File1
|----File2
|----File...
|----SubFolder01
|----SubFolder02
|----SubFolder...
|----ImportantSubFolder
|----VeryImportantSubSubFolder
|----ImportantFile01
|----ImportantFile02
|----ImportantFile...
|----ImportantFolder01...
|----ImportantFolder...
并且我需要删除“ MyFolder”中的所有内容,但不能删除“ VeryImportantSubSubFolder”中的所有内容,包括此“ VeryImportantSubSubFolder”中的所有文件/文件夹。
因此删除后,我只需要
MyFloder
|----ImportantSubFolder
|----VeryImportantSubSubFolder
|----ImportantFile01
|----ImportantFile02
|----ImportantFile...
|----ImportantFolder01...
|----ImportantFolder...
非常感谢!
这应该可以解决问题:
$folder = 'C:\myfolder\'
Get-ChildItem -Path $folder | ForEach-Object {
if( !$_.PSIsContainer ) {
Remove-Item -Path $_.FullName -Force | Out-Null
}
}