Python os.fwalk() Method
Example
Travers all the branch of a specified path with file descriptor:
#Import os Library
import os
# Travers all the branch of specified path with file descriptor
for(root, dirs, files, rootfd) in os.fwalk('/var/'):
print("Directory path: %s"%root)
print("Directory Names: %s"%dirs)
print("Files Names: %s"%files)
print("File Discriptor: %s"%rootfd)
Try it Yourself »
Definition and Usage
The os.fwalk() method behave exactly same like os.walk(), except that it yields a 4-tuple that contain directory path, directories name, files name and file descriptor.
Note: Available only on UNIX platforms.
Syntax
os.fwalk(top='.', topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=None)
Parameter Values
| Parameter | Description |
|---|---|
| top | Required. Represent path-like object to be traversed. |
| topdown | Optional. Represent topdown approach by default. If specified False the bottomup approch is implemented. |
| onerror | Optional. Represent an OSError. The default value of onerror is none but it is specified it should be a function that can report the error to continue with the walk, or raise an exception to abort the walk. |
| follow_symlinks | Optional. Represent a boolean value either True or False. If its True method will follow the symbolic link. |
| dir_fd | Optional. Represent a directory. The default value of this parameter is None. |
Technical Details
| Return Value: | Tuple |
|---|---|
| Python Version: | 3.3 |
| Change Log: | 3.6- Accepts a path-like object 3.7- Added support for bytes paths. |