Discuss / Python / dir_l

dir_l

Topic source

雲☁

#1 Created at ... [Delete] [Delete and Lock User]

import os

from datetime import datetime

def print_dir(filename):

    mtime = os.path.getmtime(filename)

    # 获取修改文件的时间戳

    mtime_string = datetime.fromtimestamp(int(mtime))

    # 获取修改文件时间mtime

    test_size = os.path.getsize(filename)

    # 获取文件大小

    print(mtime_string, filename, test_size, 'Bytes')

def dir_l(path):

    s = ([i for i in os.listdir(path)])

    for i in s:

        print_dir(i)

if __name__ == "__main__":

    dir_l(os.path.abspath('.'))


  • 1

Reply