~1 min read • Updated Oct 1, 2025
Program Overview
This Python program displays structured information that is easy to find and navigate.
It can be used to list files, show system details, or organize data in a readable format.
In this example, we’ll list all files in a given directory with their sizes and last modified dates.
Python Code:
import os
from datetime import datetime
# Read target directory from user
directory = input("Enter directory path: ")
# List and display file info
print("\n--- File Information ---")
for filename in os.listdir(directory):
filepath = os.path.join(directory, filename)
if os.path.isfile(filepath):
size = os.path.getsize(filepath)
modified = datetime.fromtimestamp(os.path.getmtime(filepath))
print(f"{filename} | {size} bytes | Last modified: {modified.strftime('%Y-%m-%d %H:%M:%S')}")
Sample Output:
Enter directory path: ./docs
--- File Information ---
report.pdf | 24567 bytes | Last modified: 2025-09-28 14:22:10
summary.txt | 1024 bytes | Last modified: 2025-09-30 09:05:44
Step-by-Step Explanation:
- The user enters a directory path
- The program loops through all files in that directory
- For each file, it displays the name, size in bytes, and last modified timestamp
- The output is formatted for easy scanning and retrieval
Written & researched by Dr. Shahin Siami