首页 > 解决方案 > 目录中的所有文件未在 python 中显示

问题描述

以下代码是我所拥有的,运行时它显示 1246 个文件,但是当我使用 *. 在驱动器上的搜索文件夹区域中,我看到它们是 5,936 个文件。我怎样才能解决这个问题?谢谢

def walk_error(error):
        print(error.filename)
    
    for root, dirs, files in os.walk(r'D:/', onerror=walk_error):
        for name in files:
            tst2.append(name)
            nm.append(name) # Get Name of File
            r.append(os.path.join(root, name))  # Get path way of file
    
            created =(os.path.getctime(os.path.join(root, name))) #get creation date of file
            p.append(time.ctime(created)) #Add format date of file to list
    
            split_tup = os.path.splitext(os.path.join(root, name)) # Seperate into two tuples
            su.append(split_tup) #append tuples to list
    
            file_name = split_tup[0] # Get file name without extension
            fn.append(file_name) #Add file name with out extenion to list

        file_extension = split_tup[1] # Get file extension
        fe.append(file_extension) # Add extension to list
       

    for i in range(1, len(files)):
        a = sheet.cell(row=1+i,column =1)
        a.value = i

        b = sheet.cell(row=1+i,column =2)
        b.value = nm[i]

        c = sheet.cell(row=1+i, column = 3)
        c.value = fe[i]

        d = sheet.cell(row=1+i, column = 4)
        d.value = p[i]
    
        e = sheet.cell(row=1+i,column =5)
        e.value = '=HYPERLINK("{}", "{}")'.format(r[i],'Link to file completed how can I get Created by properties?')

标签: pythonpython-3.xfiledirectory

解决方案


推荐阅读