The goal of the code is that whenever user gives a line of string as input, the program should print all paths to every file, directory, sub directory that are under consideration (which means the input string is included in the file or directory name or included in the file-paths)
The problem of this code is that whenever I run the whole program, the "alist.extend(check_name(name,str(f)))" in the check_name function will run too many times that exceeds the default recursive limit and change the default number is not gonna help.
I tried to increase the default recursive limit to 2000, 3000, 4000, but it still didn't work. When i increased to 100000, it crashed.
def aopen(a:str,b:str) -> list:
path = Path(b)
alist =[]
for p in path.iterdir():
if p.is_file():
alist.append(p)
elif p.is_dir():
alist.append(p)
alist.extend(aopen(a,p))
return alist
def check(name:str,path:str) -> list:
alist=[]
path0 = Path(path).cwd()
for f in path0.iterdir():
if name in str(f):
if f.is_file():
alist.append(f)
elif f.is_dir():
alist.extend(aopen(name,str(f)))
elif name not in str(f) and f.is_dir():
alist.extend(check(name,str(f)))
return alist
def p():
alist = []
while True:
link = input()
if link == 'done-for-now':
break
alist = check(link,'..')
if alist == []:
print("NOT FOUND")
continue
else:
for i in alist:
print(i)
p()
The expected output should be a list of paths printed in the shell.