![]() |
VOOZH | about |
Given a folder that contains multiple files, the task is to go through each file and read its content one by one. For Example:
Folder structure:
docs/
├── a.txt -> "Hello"
├── b.txt -> "Python"
└── c.txt -> "Files"Output: a.txt Hello
b.txt Python
c.txt Files
Explanation: Python visits every file inside the docs folder, opens it, reads its text, and prints both the file name and its content.
This method reads directory entries directly using os.scandir() and provides both file names and their full paths, which allows files to be opened without extra path handling.
Output
Explanation:
This method uses pathlib module which treats folders and files as objects, allowing direct access to file names and contents in a clean way.
Output
Explanation:
os.walk() recursively iterates through a directory tree. It returns the current path, a list of subfolders, and a list of files, making it ideal for processing entire directory structures.
Output
Explanation:
glob module allows file searching using wildcard patterns. It is helpful when you want to filter files by extension or match specific filename patterns in a directory.
Output
Explanation: