Python os.lstat() Method
Example
Get status of a file:
#Import os Library
import os
#Get status of a file
print (os.lstat("test.txt"))
Definition and Usage
The os.lstat()
method returns the status of a file or file descriptor, but does not follow symbolic links.
This is equivalent to os.stat(path, dir_fd=dir_fd, follow_symlinks=False)
.
Path may be specified either as a string or as bytes, directly or indirectly through the PathLike interface or as a file descriptor. This status includes information about a file associated with a file descriptor.
Note: Available on WINDOWS and UNIX platforms.
Syntax
os.lstat(path, dir_fd)
Parameter Values
Parameter | Description |
---|---|
path | Required. Path of the file/directory to get the status |
dir_fd | Optional. A file descriptor referring to directory. Default value None |
Technical Details
Return Value: | A stat_result object, representing system configuration information in terms of,st_mode - protectionst_ino - inode numberst_dev - ID of device containing filest_nlink - number of hard linksst_uid - user ID of ownerst_gid - group ID of ownerst_size - total size, in bytesst_atime - time of last accessst_mtime - time of last modificationst_ctime - time of last status change |
---|---|
Python Version: | pre-2.6 |
Change log: |
3.3- Added the dir_fd paramete 3.6- Accepts a path-like object for src and dst 3.8- On Windows, now opens reparse points that represent another path (name surrogates), including symbolic links and directory junctions |