Algorithm


1. Start
2. Prompt the user for the file path
3. Try to open the file with the given path
4. If the file is not found, display an error message and exit
5. Get the size of the file using the file's metadata
6. Close the file
7. Display the file size to the user
8. End

Code Examples

#1 Code Example- Python Programing Using os module

Code - Python Programming

import os

file_stat = os.stat('my_file.txt')
print(file_stat.st_size)
Copy The Code & Try With Live Editor

Output

x
+
cmd
34

#2 Code Example- Python Programing Using pathlib module

Code - Python Programming

from pathlib import Path

file = Path('my_file.txt')
print(file.stat().st_size)
Copy The Code & Try With Live Editor

Output

x
+
cmd
34
Advertisements

Demonstration


Python Programing  to Check the File Size-DevsEnv