该代码应通过当前目录中的所有顶级目录,并执行临时文件检查,如果不存在,它将移动目录。
$processDirectories = {
foreach ($childDirectory in Get-ChildItem -Force -Directory) {
test-path "$childDirectory\*.tmp"
move-item -LiteralPath "$childDirectory" -Destination "d:\"
}
}
我不知道如何停止为找到
*.tmp
的目录运行代码。另外,此方法仅检查每个子目录的根是否为*.tmp
,而不是其中的整个树。
最佳答案
如果我了解您的限制,这里有两个变体,
计算子文件夹中*.tmp
的数量。如果为零,则移动文件夹。
foreach ($childDirectory in Get-ChildItem -Force -Directory) {
if ((Get-ChildItem $childDirectory -recurse -Include *.tmp, *.!qb).Count -eq 0){
Move-Item -LiteralPath "$childDirectory" -Destination "d:\" -WhatIf
}
}
Get-ChildItem -Force -Directory | Where-Object {
(Get-ChildItem $_ -recurse -Include *.tmp, *.!qb).Count -eq 0} |
Move-Item -Destination "d:\" -WhatIf
如果输出看起来正常,请删除结尾的
-WhatIf
关于powershell - * .tmp是否存在于目录中,如何不对目录进行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56092908/