我想在我们的用户配置文件中识别特定的空文件夹。
我有一个文本文件,其中包含我希望脚本引用的所有用户名。该脚本将循环每个用户目录,并输出到文件或屏幕,并说明该目录是否为空。隐藏文件不必计数!
类似的东西
FOR /F %U IN (C:\UserList\UserList.TXT) DO *Find and List Empty Folder* \\Server\Share\%U\Target_Folder
欢迎使用 Powershell 解决方案!
最佳答案
This article Technet 上提供了以下 Powershell 代码片段来识别所有空文件夹:
$a = Get-ChildItem C:\Scripts -recurse | Where-Object {$_.PSIsContainer -eq $True}
$a | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName
将“C:\Scripts”替换为您要搜索的根文件夹。
更新:
以下脚本将帮助您了解大致情况。
$content = Get-Content C:\Temp\FolderList.txt
foreach ($line in $content)
{
Write-Host $line -NoNewline
$testObject = Test-Path -Path $line
if ($testObject)
{
$folder = Get-Item -Path $line
$filesCount = $folder.GetFiles().Count
if ($filesCount.Equals(0))
{
Write-Host " - Empty folder"
}
else
{
Write-Host " - Contains files"
}
}
else
{
Write-Host " - Invalid path"
}
}
关于powershell - 识别空文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33802865/