识别空文件夹 [英] Identify Empty Folders

查看:73
本文介绍了识别空文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我们的用户个人资料中标识一个特定的空文件夹.

I would like to identify a specific empty folder in our user profiles.

我有一个文本文件,其中包含我希望脚本引用的所有用户名.该脚本将循环每个用户目录,并输出到文件或屏幕,并说明该目录是否为空.隐藏的文件不必计算!

I have a text file containing all of our user names that I want the script to refer to. The script will loop each user directory and either output to file or screen and say if the directory is empty. Hidden files do not have to count!

类似的东西

FOR /F %U IN (C:\UserList\UserList.TXT) DO *Find and List Empty Folder* \\Server\Share\%U\Target_Folder

欢迎使用Powershell解决方案!

Powershell solutions welcome!

推荐答案

本文在Technet上提供了以下Powershell代码段,以识别所有空文件夹:

This article on Technet provides the following Powershell code snippet to identify all empty folders:

$a = Get-ChildItem C:\Scripts -recurse | Where-Object {$_.PSIsContainer -eq $True}
$a | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName

用您要搜索的根文件夹替换"C:\ Scripts".

Replace "C:\Scripts" with the root folder you want to search.

更新:

以下脚本将带您进入球场.

The following script will get you in the ballpark.

$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"
    }

}

这篇关于识别空文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆