当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell 获取文件元数据

作者:精品下载站 日期:2024-12-14 16:46:15 浏览:15 分类:玩电脑

PowerShell 获取文件元数据


PowerShell 中的 Get-ChildItem 命令用于在指定位置再获取一项。当我们指定文件路径时,Get-ChildItem 获取文件对象并使用Format-List * 获取文件元数据并显示它。

在本文中,我们将讨论如何使用 Get-ChildItem 命令获取文件元数据以及获取 mp3 文件元数据。

PowerShell 获取文件元数据

使用 PowerShell 中的 Get-ChildItem cmdlet 获取指定的文件,并使用 Format-List * 获取文件属性或元数据并将其显示在终端上。

Get-ChildItem .\powershell-read-file-line-by-line.png | Format-List *        

在PowerShell脚本中,我们使用Get-ChildItem命令来获取文件对象。然后它传递文件对象 Format-List * 来获取文件元数据。

上述脚本获取文件 powerShell-read-file-line-by-line-.jpg 的文件元数据的输出为:

[玩转系统] PowerShell 获取文件元数据

酷提示:如何在 PowerShell 中逐行读取文件!

PowerShell 获取 mp3 文件元数据

带 Format-List * 的 Get-ChildItem 命令检索 mp3 文件元数据。

Get-ChildItem .\PowerShell-Check-File-Exists.mp4 | Format-List *  

在上面的 PowerShell 脚本中,Get-ChildItem 命令获取 mp3 文件对象并将其通过管道传输到 Format-List。格式列表 * 列出所有 mp3 文件属性并将它们显示在终端上。

上述脚本的输出获取 mp3/mp4 文件元数据,如文件名、mp3 文件长度、创建日期、最后写入时间等。

[玩转系统] PowerShell 获取文件元数据

酷提示:如何使用 PowerShell 获取文件所有者名称!

结论

希望上述在PowerShell中获取文件元数据的文章对您有所帮助。

在 PowerShell 中使用 Get-ChildItem 命令从指定位置获取一项或多项,并使用 Format-List * 列出所有文件属性。文件可以是文本、图像、mp3、视频或音频。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯