Using python I am trying to os.walk a directoy and input file info into an excel file

  python-3.x

I have successfully made a os.scandir version of this with single directory output, but I am running into issues when trying to use os.walk, here I am trying to nest the functions, but the output is still single directory. My goal is to get the file info data for all sub directories. Thanks

for root, dirs, files in os.walk(scanpoint):
df1 = pd.DataFrame([])
for dir in dirs:
    
    with os.scandir(scanpoint) as entries:
        for entry in entries:
            info = entry.stat()
            df = pd.DataFrame({'Name':[entry.name],
                            'Path':[entry.path],
                            'Size':[get_size_format(info.st_size)],
                            'created':[datetime.datetime.fromtimestamp(info.st_ctime)],
                            'Modified':[datetime.datetime.fromtimestamp(info.st_ctime)], 
                            'Last Opened':[datetime.datetime.fromtimestamp(info.st_atime)],
                            'File Extension:':[os.path.splitext(entry.name)[1]],
                            'Bytes':[info.st_size]},
                            index = [0])
            df1 = df1.append(df)
            writer = ExcelWriter(r'C:UsersAndreyDesktopFolder Info Scan.xlsx')
            df1.to_excel(writer,'Sheet1', index=False)   
    writer.save() 

Source: Python-3x Questions

LEAVE A COMMENT