How to access file properties in Windows Vista using Python?

The question is as simple as the title, how do I access the properties of Windows files, for example, taking into account the date and, more specifically, using Python? For the program I'm doing, I need to get lists of all tags in different files in a specific folder, and I'm not sure how to do this. I have a win32 module, but I do not see what I need.

Thank you guys for the quick answers, however, the main stat that I need from the files is the tag attribute, which is now included in Windows Vista, and unfortunately it is not included in the os.stat and stat modules. Thank you, though, as I need this data, but it was more after reflection on my part.

+3
source share
4 answers

You can use os.stat with stat

import os
import stat
import time

def get_info(file_name):
    time_format = "%m/%d/%Y %I:%M:%S %p"
    file_stats = os.stat(file_name)
    modification_time = time.strftime(time_format,time.localtime(file_stats[stat.ST_MTIME]))
    access_time = time.strftime(time_format,time.localtime(file_stats[stat.ST_ATIME]))
    return modification_time, access_time

You can get a lot of other statistics, check the stat module for a complete list. To extract information about all files in a folder, use os.walk

import os
for root, dirs, files in os.walk(/path/to/your/folder):
    for name in files:
        print get_info(os.path.join(root, name))
+7
source

Apparently, you need to use the Windows search API that System.Keywords is looking for - you can access the API directly ctypesor indirectly (requires win32 extensions ) through the COM Interop API assembly . Sorry, I donโ€™t have vista installed for verification, but I hope these links are useful!

+3
source

:

import time, datetime
fstat = os.stat(FILENAME)
st_mtime = fstat.st_mtime # Date modified
a,b,c,d,e,f,g,h,i = time.localtime(st_mtime)
print datetime.datetime(a,b,c,d,e,f,g)
+1

( , .)

  • Download and install the pywin32 extension .
  • Grab the code Tim Golden wrote for this very task.
  • Save the Tim code as a module on your own computer.
  • Call the method of property_setsyour new module (supplying the necessary path to the file). The method returns a generator that is iterable. See the following sample code and output.
0
source

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


All Articles