In a VERY filled directory on Windows operating system with hundreds of sub-directories and thousands of files, I'm trying to pull out where the files (raw path + file name) are along with the 'Owner' attribute of the file and log that; essentially a simple two column table with FILE and OWNER. I don't really care about the output format (.csv, .xls, xlsx, etc.) as long as it can be written out and is structured - I am focusing on getting the output first. Here is my attempt with dir as an example.
import os
import pandas as pd
file_list=[]
owner_list=[]
dir = r'Downloads'
# r=root, d=directories, f = files
for r, d, f in os.walk(dir):
for file in f:
file_list.append(os.path.join(r, file))
owner_list.append('???')
df = pd.DataFrame({'File': [file_list],
'Owner': [owner_list]})
print(df)
I'm having a very hard time getting the owner attribute. With Google's help, I don't think
stat(my_filename).st_uid
-is the right function to use because it's returning an ID instead of an actual name. What are some possible solutions?