This Python program receives the path to a file and displays its key attributes.
The displayed properties include file name, full path, size in bytes, last access time, and last modification time.
This is useful for file inspection, logging, or system auditing.
import os
import time
# Get file path from user
file_path = input("Enter the file path: ")
# Check if the file exists
if not os.path.isfile(file_path):
print("File not found.")
else:
print("\n--- File Attributes ---")
print("File Name:", os.path.basename(file_path))
print("Full Path:", os.path.abspath(file_path))
print("Size (bytes):", os.path.getsize(file_path))
print("Last Access Time:", time.ctime(os.path.getatime(file_path)))
print("Last Modification Time:", time.ctime(os.path.getmtime(file_path)))
Enter the file path: D:/Data/info.txt
--- File Attributes ---
File Name: info.txt
Full Path: D:/Data/info.txt
Size (bytes): 2048
Last Access Time: Sat Sep 27 18:30:00 2025
Last Modification Time: Sat Sep 27 18:20:00 2025
- The file path is received using input()
- os.path.isfile() checks if the file exists
- os.path.basename() extracts the file name
- os.path.abspath() returns the full path
- os.path.getsize() returns the file size in bytes
- os.path.getatime() and getmtime() return access and modification times
- time.ctime() converts timestamps to readable format