在Python中,你可以使用os
模塊來查看文件的屬性。以下是一些常用的方法:
os.stat()
函數獲取文件屬性:import os
file_path = 'your_file_path_here'
file_stats = os.stat(file_path)
print("文件名:", file_stats.st_name)
print("文件大小:", file_stats.st_size, "字節")
print("創建時間:", os.ctime(file_stats.st_ctime))
print("修改時間:", os.ctime(file_stats.st_mtime))
print("訪問時間:", os.ctime(file_stats.st_atime))
print("文件權限:", oct(file_stats.st_mode))
os.path
模塊獲取文件屬性:import os
file_path = 'your_file_path_here'
print("文件名:", os.path.basename(file_path))
print("文件目錄:", os.path.dirname(file_path))
print("文件擴展名:", os.path.splitext(file_path)[1])
print("文件權限:", oct(os.path.stat(file_path).st_mode))
注意:在這些示例中,將your_file_path_here
替換為你要查看屬性的文件的實際路徑。