def search_filename(fn :str, scope): #posixpath
res = list()
for file_ in Path(scope).iterdir(): # file_ is automatically posixpath
if file_.is_dir():
search_filename(fn, os.path.join(str(scope), file_))
if fn in str(file_.resolve()):
res.append(str(file_.resolve()))
return res
했는데 'pdf'로 돌려도 다 안 잡혀서 뭐가 문젠가 이틀 동안 고민했는데 그냥 재귀 함수 안에서 바깥 res를 접근을 못하는 거였다.
def search_filename(fn :str, scope): #posixpath
res = list()
for file_ in Path(scope).iterdir(): # file_ is automatically posixpath
if file_.is_dir():
r2 = search_filename(fn, os.path.join(str(scope), file_))
res.extend(r2)
if fn in str(file_.resolve()):
res.append(str(file_.resolve()))
return res
로 해결. 근데 함수 바깥에서 함수 내의 지역 변수는 참조 못해도 함수 안에서 바깥에 있는 변수는 글로벌 선언 없이 참조할 수 있는 거 아니었나.. 아니면 res 선언 자체가 search_filename 함수 안에서 선언돼서 이것도 로컬 변수로 잡히는건가 #TIL