我想在树上搜索一个文件。
我知道文件名和树根,但我想找到文件路径。我在windows 7上使用python-3.4。
我有:
#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.你们有办法这么做吗?
请记住,我不想在python中添加任何lib或plugin。
谢谢,
致以敬意,
https://stackoverflow.com/questions/24142924
复制相似问题