Created
February 26, 2010 02:37
-
-
Save lxneng/315330 to your computer and use it in GitHub Desktop.
Find file in subdirectory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def findFileInSubdirectory(filename, subdirectory=''): | |
''' | |
Find file in subdirectory | |
''' | |
if subdirectory: | |
path = subdirectory | |
else: | |
path = os.getcwd() | |
for root, dirs, names in os.walk(path): | |
if filename in names: | |
return os.path.join(root, filename) | |
raise 'File not found' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment