[英]Find a file in a tree in python-3.4 on windows
I want to search a file in a tree. 我想在树中搜索文件。
I know the filename and the root of the tree, but I want to find the file path. 我知道文件名和树的根,但是我想找到文件路径。 I use python-3.4 on windows 7.
我在Windows 7上使用python-3.4。
I have: 我有:
#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
I also have a tree ( something/ is a folder): 我也有一棵树(something /是一个文件夹):
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/
etc it's an example but it's really close of my real case. 等等,这只是一个例子,但这与我的真实情况非常接近。
I want: 我想要:
#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
I precise that it should be generic, so I can't make hard link or hard path etc. 我精确地说,它应该是通用的,所以我不能进行硬链接或硬路径等。
For the moment I've try some tricky scripts with some os.listdir etc but it seems messy and don't always work. 目前,我已经尝试了一些棘手的脚本以及一些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.
Do you guys have some way to do this ? 你们有办法吗?
Keep in mind that I don't want to add any lib or plugin to my python. 请记住,我不想向我的python添加任何库或插件。
Thank you, 谢谢,
Regards, 问候,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.