简体   繁体   English

有没有办法使用powershell在文件夹上找到“元数据”

[英]Is there any way to find 'metadata' on folders using powershell

So I want to know if any of the folders in a directory have any subfolders or files in them, I tried just looking at the directory in PowerShell but it gave me only mode, last write time, and name.所以我想知道目录中的任何文件夹中是否有任何子文件夹或文件,我尝试只在 PowerShell 中查看该目录,但它只给了我模式、上次写入时间和名称。 Is there any way of adding to this list to include metadata of the folder like size or number of subfiles/folders all I want to know is if they are empty or not so there may be a simpler way I'm missing.有什么方法可以添加到此列表中以包含文件夹的元数据,例如大小或子文件/文件夹的数量,我只想知道它们是否为空,因此可能缺少一种更简单的方法。

Thanks for any help you can give!谢谢你提供的所有帮助!

I see the question is tagged 'windows', so on Windows you could also use a COM object.我看到问题被标记为“windows”,因此在 Windows 上您也可以使用 COM 对象。

$fso = New-Object -ComObject Scripting.FileSystemObject

$folder = $fso.GetFolder($pathToFolder)

$folder will be an object with a bunch of interesting metadata on it, including SubFolders and Files. $folder 将是一个带有一堆有趣元数据的对象,包括子文件夹和文件。 One of the interesting ones is Size.其中一个有趣的是大小。 If Size is zero, there are no files in that directory, or in any nested subdirectories either.如果 Size 为零,则该目录或任何嵌套子目录中都没有文件。

If you just want to know if there are folders/subfolders and/or files then this will work:如果您只想知道是否有文件夹/子文件夹和/或文件,那么这将起作用:

$folder="C:\Test"

 Get-ChildItem $folder -Recurse | Measure-Object

Output (in my case)输出(在我的情况下)

Count    : 2
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

If you want to see more properties then this might work for you:如果您想查看更多属性,那么这可能适合您:

Get-ChildItem -Path $folder -Recurse   | Format-List *

alternatively you can also select the first x, last x, or even skip items:或者,您也可以选择第一个 x、最后一个 x,甚至跳过项目:

Get-ChildItem -Path $folder -Recurse |Select-Object -First 2| Format-List *

*-Recurse will check all folders below *-Recurse 将检查下面的所有文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM