I want to check if a given file is within a specific directory and it's including subdirectories .
I used this code :
def Grep(givenfile,givendir):
# iterate top down till in directory path
for (root,dirs,files) in os.walk(givendir):
if givenfile in files:
# if file present return true
return True
return False
## Test.py my file that contain my code
##C://Users//LENOVO//Desktop//python2021 this my path that contain my files
Grep("Test.py",r"C://Users//LENOVO//Desktop//python2021")
When i run the code that is no output shown ?
Is there a better way to check if a given file is within a specific directory and it's including subdirectories
Thanks