1

I have been using the replies from here to read out the metadata of files on windows. However i noticed that it would just ignore hidden files.

How can one also include hidden files in this approach?

J.N.
  • 153
  • 1
  • 9

1 Answers1

1

You can combine python's os library with Windows' Shell.Application object, as done here, something like this:

import os
import win32com.client

sh = win32com.client.gencache.EnsureDispatch('Shell.Application', 0)
path = r'c:\mypath\myfolder'
ns = sh.NameSpace(path)

colnum = 0
columns = []
while True:
    colname=ns.GetDetailsOf(None, colnum)
    if not colname:
        break
    columns.append(colname)
    colnum += 1

for name in os.listdir(path): # list all files
    print(path + '\\' + name)
    item = ns.ParseName(name)
    for colnum in range(len(columns)):
        colval=ns.GetDetailsOf(item, colnum)
        if colval:
            print('\t', columns[colnum], colval)

hidden files will display (H attribute is for Hidden)

...
Attributes HA
...
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • I probably should have thought of that myself... instead i went digging around here https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellfolder-enumobjects. Thanks so much! – J.N. Feb 05 '23 at 20:22
  • @J.N. - Shell.Application is a wrapper over these native API and interfaces. – Simon Mourier Feb 05 '23 at 21:18