1

I'm trying to find a way in Python to add metadata to a file. For example, if I wanted to add a property "source" with a value of "friend" to a file called "CookingRecipe.txt", the end result should be that when I right-click on "CookingRecipe.txt", go to Properties, and go to the "Details" tab, I should see a "Property" below called "source" followed by a "Value" right next to it called "friend".

Here is my code. When the file gets created, I don't see the "source" property with the "friend" value added.

f = open("CookingRecipe.txt", "x")
f.fileinfo = {'source': 'friend'}
f.close()

Please help and thank you very much!

qccaprospect
  • 141
  • 1
  • 5
  • 14
  • Possible duplicate of [Python add custom property/metadata to file](https://stackoverflow.com/questions/41183819/python-add-custom-property-metadata-to-file) – buræquete Jul 31 '19 at 21:46
  • @buraequete: I tried the suggested method in that link but it didn't work for me. I'm trying to do this on Windows. – qccaprospect Aug 22 '19 at 23:46
  • Related? [Reading metadata with Python](https://stackoverflow.com/q/12521525/4518341) – wjandrea Aug 23 '19 at 01:58
  • @wjandrea: Thanks for the link, but I'd like to be able to "add" metadata to a new or old file. – qccaprospect Aug 23 '19 at 05:17
  • @qccaprospect Yeah, the link mentions some APIs for *getting* metadata, so *setting* metadata should be similar I'd think. – wjandrea Aug 23 '19 at 13:15

0 Answers0