Python: Get the size, permissions, owner, device, created, last modified and last accessed date time of a specified path
Python Operating System Services: Exercise-5 with Solution
Write a Python program to get the size, permissions, owner, device, created, last modified and last accessed date time of a specified path.
Sample Solution:
Python Code :
import os
import sys
import time
path ='g:\\testpath\\'
print('Path Name ({}):'.format(path))
print('Size:', stat_info.st_size)
print('Permissions:', oct(stat_info.st_mode))
print('Owner:', stat_info.st_uid)
print('Device:', stat_info.st_dev)
print('Created :', time.ctime(stat_info.st_ctime))
print('Last modified:', time.ctime(stat_info.st_mtime))
print('Last accessed:', time.ctime(stat_info.st_atime))
Sample Output:
Path Name (g:\testpath\): Size: 546 Permissions: 0o100666 Owner: 0 Device: 4235770541 Created : Wed Jan 15 11:21:42 2020 Last modified: Thu Jan 16 15:32:11 2020 Last accessed: Thu Jan 16 15:32:11 2020
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to check for access to a specified path. Test the existence, readability, writability and executability of the specified path.
Next: Write a Python program to create a symbolic link and read it to decide the original file pointed by the link.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Python: Unknown Arguments Using *arguments
If your function can take in any number of arguments then add a * in front of the parameter name:
def myfunc(*arguments): for a in arguments: print a myfunc(a) myfunc(a,b) myfunc(a,b,c)
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework