Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - how to set "title" in extended file properties

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?

like image 631
Tristan P Avatar asked May 19 '13 19:05

Tristan P


1 Answers

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.

like image 153
Lars Truijens Avatar answered Nov 16 '22 00:11

Lars Truijens