0
트리에서 파일을 검색하고 싶습니다.Windows의 python-3.4 트리에서 파일 찾기
파일 이름과 트리의 루트를 알고 있지만 파일 경로를 찾고 싶습니다. 나는 창문에 파이썬 3.4을 사용 7.
내가 가진 :
#I have a list with C header file name => my_headers_list that look like:
for part in my_headers_list:
print(part)
#show this
common.h
extern.h
something.h
else.h
나는 또한 나무가 (뭔가 /있는 폴더) :
Software/
something.c
Component1/
extern.c
extern.h
Component2/
Core/
common.h
common.c
Config/
common_m.c
common_m.h
Component3/
Managment/
Core/
Config/
등이 예입니다하지만 정말 내 진짜 사건의 종결.
내가 원하는 :
#a list like the first one, but with the full path of the files
for part in my_headers_list:
print(part)
#show this
Software/Component2/Core/common.h
Software/Component1/extern.h
Software/Component3/Core/something.h
Software/Component3/Management/else.h
나는 정확한 것이 일반적인해야한다, 그래서 나는 몇 가지 까다로운 스크립트를 시도했습니다 당분간 등 하드 링크 또는 하드 경로
을 할 수없는 일부 os.listdir 등하지만 그것은 지저분 해 보입니다 항상 작동하지 않습니다.
#I try something like this
dirs = os.listdir("Software/")
for part in dirs:
#don't know how to correctly manage these informations to get what I want.
혹시이 방법이 있습니까?
파이썬에 lib 또는 plugin을 추가하고 싶지 않습니다.
는감사 의견에서 해결
['os.walk' (https://docs.python.org/2/library/os.html#os.walk) – Kevin
또는 ['glob'] (https://docs.python.org/2/library/glob.html) – Lafexlos
3.4를 사용하고 있다면 ['pathlib'] (https://docs.python.org/3/library/pathlib)도 있습니다. html) 당신이 OO 스타일을 선호한다면. –