
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to check the permissions of a file using Python?
You can use os.access(path, mode) to check the file permission with modes for reading, writing and execution permissions. For example,
>>> import os >>> os.access('my_file', os.R_OK) # Check for read access True >>> os.access('my_file', os.W_OK) # Check for write access True >>> os.access('my_file', os.X_OK) # Check for execution access False >>> os.access('my_file', os.F_OK) # Check for existance of file True
You can also use os.stat to get the status of a file or a file descriptor. It is quite complex to interpret as it uses bitmasks to identify the permissions. You can read mode about it here: https://docs.python.org/3/library/os.html#os.stat
- Related Articles
- How to check the permissions of a directory using Python?
- How to change file permissions in Python?
- How to set file permissions in Java?
- How to check the Existence of a File using Java?
- How to check the Existence of a File using C#?
- How to check file last access time using Python?
- How to check if a file exists or not using Python?
- How to change the user and group permissions for a directory using Python?
- How to Copy File Permissions and Ownership to Another File in Linux?
- File Permissions in java
- File Permissions in C#
- How do I check whether a file exists using Python?
- Advanced File Permissions in Linux
- How to change the permission of a file using Python?
- How to change the mode of a file using Python?

Advertisements