w3resource

Python: Retrieve file properties

Python Basic: Exercise-107 with Solution

Write a Python program to retrieve file properties.

Sample Solution:-

Python Code:

import os.path
import time

print('File         :', __file__)
print('Access time  :', time.ctime(os.path.getatime(__file__)))
print('Modified time:', time.ctime(os.path.getmtime(__file__)))
print('Change time  :', time.ctime(os.path.getctime(__file__)))
print('Size         :', os.path.getsize(__file__))

Sample Output:

File         : 8dbacd90-266d-11e7-a9c1-cf681af3cdf1.py             
Access time  : Fri Apr 21 14:06:03 2017                            
Modified time: Fri Apr 21 14:06:02 2017                            
Change time  : Fri Apr 21 14:06:02 2017                            
Size         : 304   

Flowchart:

Flowchart: Retrieve file properties.

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to divide a path on the extension separator.
Next: Write a Python program to find path refers to a file or directory when you encounter a path name.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]