mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-18 07:17:06 +00:00
find files
This commit is contained in:
parent
7d879b4e33
commit
75c8f46f4a
18
useful_scripts/find_file.py
Normal file
18
useful_scripts/find_file.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Sebastian Raschka 2014
|
||||
#
|
||||
# A Python function to find files in a directory based on a substring search.
|
||||
|
||||
|
||||
import os
|
||||
|
||||
def find_files(substring, path):
|
||||
results = []
|
||||
for f in os.listdir(path):
|
||||
if substring in f:
|
||||
results.append(os.path.join(path, f))
|
||||
return results
|
||||
|
||||
# E.g.
|
||||
# find_files('Untitled', '/Users/sebastian/Desktop/')
|
||||
# returns
|
||||
# ['/Users/sebastian/Desktop/Untitled0.ipynb']
|
Loading…
Reference in New Issue
Block a user