Created
April 16, 2020 12:26
-
-
Save asadamatic/325cae3dbf96efa04b21480e9dfe9f3d to your computer and use it in GitHub Desktop.
Searching for a file in a directory with sub directories and returning file paths using python.
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, os.path | |
def extendedFileSearch(requiredFile): | |
filePaths = [] | |
for file in os.listdir(): | |
if os.path.isdir(file): | |
if requiredFile in os.listdir(file): | |
filePaths.append(os.path.abspath(requiredFile)) | |
else: | |
pass | |
else: | |
if requiredFile in os.listdir(): | |
filePaths.append(os.path.abspath(requiredFile)) | |
else: | |
pass | |
return filePaths |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment