8000 find files · adrianhust/python_reference@75c8f46 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75c8f46

Browse files
committed
find files
1 parent 7d879b4 commit 75c8f46

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

useful_scripts/find_file.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Sebastian Raschka 2014
2+
#
3+
# A Python function to find files in a directory based on a substring search.
4+
5+
6+
import os
7+
8+
def find_files(substring, path):
9+
results = []
10+
for f in os.listdir(path):
11+
if substring in f:
12+
results.append(os.path.join(path, f))
13+
return results
14+
15+
# E.g.
16+
# find_files('Untitled', '/Users/sebastian/Desktop/')
17+
# returns
18+
# ['/Users/sebastian/Desktop/Untitled0.ipynb']

0 commit comments

Comments
 (0)
0