Get a list of metadata associated with a file using python in Ubuntu

I am trying to get a list of metadata associated with a file using python in Ubuntu.

Without using python, the extract command works very well, but I don’t know how to use it with python, I always get a message that the extract is not defined.

+1
python ubuntu
source share
3 answers

I assume that you are asking about the metadata that appears in the Windows Properties dialog box on the Summary tab. (If not, just ignore it.) Here's how I did it.

  • Download and install Python win32 extensions . This will put win32, win32com etc. into your Python [ver] / lib / site-packages. They lead win32api, win32com, etc. For some reason, I could not get Python 2.6 (in build 216) to work. I upgraded my system to Python 2.7 and used build 216 for Python 2.7 and it worked. (To download and install, click on the link above, click on the link "pywin32", click on the link for the latest build (currently 216), click on the link for the .exe file that matches your system and Python installation (for me, it was pywin32 -216.win32-py2.7.exe ). Run the .exe file.)
  • Copy and paste the code from Get Documentation Summary Information into Tim Gold's. Py tutorial on your own computer.
  • Change the code . You really do not need to configure the code, but if you run this Tim script as the main module, and if you do not specify the path as your first sys.argv, you will get an error message. To complete the configuration, scroll down to the end of the code and omit the last block that starts with if __name__ == '__main__':

Save the file as something like property_reader.py and call its method property_sets(filepath) . This method returns a generator object. You can iterate through the generator to see all the properties and their values. You can implement it as follows:

 # Assuming 'property_reader.py' is the name of the module/file in which you saved Tim Golden code... import property_reader propgenerator = property_reader.property_sets('[your file path]') for name, properties in propgenerator: print name for k, v in properties.items (): print " ", k, "=>", v 

The output of the above code will look something like this:

 DocSummaryInformation PIDDSI_CATEGORY => qux SummaryInformation PIDSI_TITLE => foo PIDSI_COMMENTS => flam PIDSI_AUTHOR => baz PIDSI_KEYWORDS => flim PIDSI_SUBJECT => bar 
+4
source share

extract based on the libextractor library. You can access the library from Python by installing the python-extractor package on Ubuntu.

+1
source share

If you are using Windows, your question has already been addressed to fooobar.com/questions/858763 / ....

0
source share

All Articles