Discuss / Python / 作业1

作业1

Topic source

Super-String

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

第一题

import os



def list_files(path):
    for file in os.listdir(path):
        file_path = os.path.join(path, file)
        file_stat = os.stat(file_path)
        file_size = file_stat.st_size
        file_mode = file_stat.st_mode
        file_time = file_stat.st_mtime
        file_type = ''
        if os.path.isdir(file_path):
            file_type = 'd'
        elif os.path.isfile(file_path):
            file_type = '-'
        print(f'{file_type}{oct(file_mode)[-3:]} {file_size:>8} {file_time:>10} {file}')



# Example usage
list_files('.')


  • 1

Reply