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.
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.
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?
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.
You better look for another way to tag your files. Maybe NTFS Alternate Data Streams might help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With