Powershell - 如何设置“标题"在扩展文件属性中 [英] Powershell - how to set "title" in extended file properties

查看:54
本文介绍了Powershell - 如何设置“标题"在扩展文件属性中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Powershell 中编写标记系统.我希望能够在文件中设置我选择的 'tag' ,例如通过使用 'title' 字段,因为我不使用它.我想标记的文件是照片/视频和文本的混合.

I'm trying to write a tagging system in Powershell. I would like to be able to set a 'tag' of my choice in a file for example by using the 'title' field as I don't use it. The files I'd like to tag are a mixture of photos/videos and text.

我发现读取/获取扩展文件属性非常容易,因为网上有多个示例可用,但是我发现很难找到修改或写入扩展文件属性的示例;尤其是在 Powershell 中.

I've found it quite easy to read/get extended file attributes as there are multiple examples available on the net, however I'm finding it extremely difficult to find examples of modifying or writing extended file properties; especially in Powershell.

我已经设法使用 taglib-sharp 将 'titles' 写入文件,但这似乎对各种照片有问题,并且没有太多信息可用于故障排除.另外它只处理音频/视频/照片文件.

I have managed to write 'titles' to files using taglib-sharp but this seems to have problems with various photos and there is not much info available for troubleshooting. Plus it only deals with audio/video/photo files.

这是我必须阅读标题的代码(来自测试照片):

This is the code I have to read the title (from a test photo):

$path = 'C:\temp\photo.jpg'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)
$shellfolder.GetDetailsOf($shellfile, 21)

谁能告诉我如何更新此属性,然后将其写入/保存到文件中?

Can anyone tell me how I can I update this attribute and then write/save it to the file?

推荐答案

这些取决于文件格式.Windows 资源管理器只能显示这些扩展文件属性,因为插件让它知道如何获取信息.并非所有文件格式都支持这一点.例如,简单的 txt 文件没有标题.我知道没有单一的 API 来设置扩展文件属性,所以你需要找到 一个库对于您想要支持的每种文件格式.例如 TagLib-Sharp 用于照片、视频和音频以及 iTextSharp 用于 PDF.但即便如此,您也无法为所有格式设置标题,因为有些格式不支持.

These depend on the file formats. Windows Explorer is only able to show these extended file properties because plugins let it know how to get the information. Not all file formats support this. For example simple txt files don't have a title. I know of no single API to set the extended file properties, so you need to find a library for each file format you want to support. For example TagLib-Sharp for photos, videos and audio and iTextSharp for PDF. But even then you wan't be able to set the title for all formats, since some don't support it.

您最好寻找另一种方式来标记您的文件.也许 NTFS 备用数据流 可能对您有所帮助.

You better look for another way to tag your files. Maybe NTFS Alternate Data Streams might help you.

这篇关于Powershell - 如何设置“标题"在扩展文件属性中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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