Skip to content

Instantly share code, notes, and snippets.

@asadamatic
Created April 16, 2020 12:26
Show Gist options
  • Save asadamatic/325cae3dbf96efa04b21480e9dfe9f3d to your computer and use it in GitHub Desktop.
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.
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