Python: Check for access to a specified path
Write a Python program to check access to a specified path. Test the existence, readability, writability and executability of the specified path.
Sample Solution:
Python Code :
import os
print('Exist:', os.access('c:\\Users\\Public\\C programming library.docx', os.F_OK))
print('Readable:', os.access('c:\\Users\\Public\\C programming library.docx', os.R_OK))
print('Writable:', os.access('c:\\Users\\Public\\C programming library.docx', os.W_OK))
print('Executable:', os.access('c:\\Users\\Public\\C programming library.docx', os.X_OK))
Sample Output:
Exist: False Readable: False Writable: False Executable: False
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to scan a specified directory and identify the sub directories and files.
Next: Write a Python program to get the size, permissions, owner, device, created, last modified and last accessed date time of a specified path.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics