Powershell - how to set "name" in advanced file properties

I am trying to write a tag system in Powershell. I would like to be able to set the 'tag' of my choice in the file, for example, using the 'title' field, since I do not use it. The files I would like to mention are a mixture of photos / videos and text.

It was easy for me to read / get extended file attributes, as there are several examples available on the network, but it is very difficult for me to find examples of changing or writing extended file properties; especially in Powershell.

I managed to write 'titles' to files using taglib-sharp, but it seems to have problems with various photos, and there is little information to troubleshoot. Plus this applies only to audio / video / photo files.

This is the code I should read in the title (in the 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 someone tell me how can I update this attribute and then write / save it to a file?

+6
source share
1 answer

They depend on file formats. Windows Explorer can display these advanced file properties, as plugins let it know how to obtain information. Not all file formats support this. For example, simple txt files do not have a name. I do not know any APIs for setting advanced file properties, so you need to find a library for each file format that you want to support. For example TagLib-Sharp for photos, video and audio, and iTextSharp for PDF. But even then you won’t be able to set a title for all formats, as some of them do not support it.

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

+2
source

Source: https://habr.com/ru/post/945378/


All Articles