Skip to content

Commit 66e699b

Browse files
added Python Script to Search for Specific Files
1 parent 7d76916 commit 66e699b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Search_File/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Searching Specific files
2+
3+
Using the os.walk() module function and match filenames with the fnmatch module.
4+
It walks the tree top-down or bottom-up to create file names in a directory tree. It returns a 3-tuple for each directory in the tree rooted at directory top, including top itself, i.e., dirpath, dirnames, filenames.
5+
6+
## Prerequisites
7+
8+
- Python 3.x
9+
10+
## Usage
11+
12+
1. Clone the repository or download the `searching_specific_files.py` file.
13+
2. Open a terminal or command prompt and navigate to the directory where the file is located.
14+
3. Run the following command to start the program:
15+
16+
```shell
17+
python searching_specific_files.py
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# searching_specific_files.py
2+
3+
import fnmatch
4+
import os
5+
6+
root_path = '/home/tuts/Documents'
7+
_pattern = '*.mp4'
8+
9+
for _root, dirs, _files in os.walk(root_path):
10+
for _file in fnmatch.filter(_files, _pattern):
11+
print( os.path.join(_root, _file))

0 commit comments

Comments
 (0)