import os
# Function to search for a file
def search(root, word):
for path, subdirs, files in os.walk(root):
for name in files:
if word in name:
print(os.path.join(path, name))
# Driver Code
#root = '/Users'
#word = 'password'
#search(root, word)
#word = 'confidential'
#search(root, word)
from os import walk
# mypath contains the path of the current working directory
mypath = os.getcwd()
# files is a list containing the names of all files in the directory
files = []
for (dirpath, dirnames, filenames) in walk(mypath):
files.extend(filenames)
break
# print all filenames that contain the strings 'password' or 'confidential'
for file in files:
if 'password' in file or 'confidential' in file:
print(file)