41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import os
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
def walk_files(target_dir):
|
|
file_data = []
|
|
for root, dirs, files in os.walk(target_dir):
|
|
for file in files:
|
|
file_path = os.path.join(root, file)
|
|
try:
|
|
stats = os.stat(file_path)
|
|
file_info = {
|
|
'path': file_path,
|
|
'name': file,
|
|
'size': stats.st_size,
|
|
'modified': datetime.fromtimestamp(stats.st_mtime).strftime('%Y-%m-%d %H:%M:%S'),
|
|
'type': os.path.splitext(file)[1]
|
|
}
|
|
file_data.append(file_info)
|
|
except FileNotFoundError:
|
|
continue
|
|
return file_data
|
|
|
|
|
|
def print_files(file_data):
|
|
print(f"{'Name':40} {'Size (bytes)':>15} {'Modified':>20} {'Type':>10}")
|
|
print('-' * 90)
|
|
for f in file_data:
|
|
print(f"{f['name'][:38]:40} {f['size']:>15} {f['modified']:>20} {f['type']:>10}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
target = "u:\Dropbox\Ordinace\Dokumentace_ke_zpracování"
|
|
if not os.path.isdir(target):
|
|
print("Invalid directory. Please try again.")
|
|
else:
|
|
results = walk_files(target)
|
|
print_files(results)
|
|
print(f"\nTotal files found: {len(results)}")
|