Windows 10 64 位。PowerShell 5.1
当路径可以是 50 个中的任何一个时,使用 PowerShell 5 或 > 删除目录/子目录。
删除livebolivar.com
它的子目录any of 50 folders named mmddyy
"%USERPROFILE%\desktop\websites\"any of 50 folders named mmddyy"\livebolivar.com"
删除 %USERPROFILE%\desktop\websites\011920\livebolivar.com
发现太多:
gci %USERPROFILE%\desktop\websites -recurse | Where-Object {($_.PSIsContainer)} | Foreach { if ( $_.Name -eq "livebolivar.com") {remove-item $_.fullname -confirm}}
不工作:
gci -exclude favorites %USERPROFILE%\desktop\websites -recurse | Where-Object {($_.PSIsContainer)} | Foreach { if ( $_.Name -eq "livebolivar.com") {remove-item $_.fullname -confirm}}
这删除了子文件夹:
$path= @("%USERPROFILE%\desktop\websites\*\livebolivar.com")
$folders= gci -path $path -Recurse | Where-Object {$_.PsIsContainer} |Group-Object {$_.FullName.Split('_')[0] }
ForEach($folder in $folders){
$folder.Group | % { Remove-Item $_.fullname -recurse -force}}
制作测试文件夹:
pushd %USERPROFILE%\Desktop
foreach($i in -10..-1){
$z=(Get-Date).AddDays($i).tostring("MMddyy")
ni -itemtype directory $z\livebolivar.com\New Folder > $null}
ni -itemtype file $z\livebolivar.com\New Folder\test.txt > $null}
popd
exit
递归目录删除目录递归删除目录和子目录用remove-item删除目录和子目录用ri