Created
October 13, 2020 03:52
-
-
Save chenyuxiang0425/2e4db08f324af9cf4f2bdf243f6e909b to your computer and use it in GitHub Desktop.
得到文件路径在 path 中包含 filenmane_content 的文件名的 list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # path_list 是获得的所有包含 text 的绝对路径的list | |
| def get_all_path(path_list,path,filenmane_content): | |
| paths = os.listdir(path) # 列出指定路径下的所有目录和文件 | |
| for i in paths: | |
| com_path = os.path.join(path,i) | |
| if os.path.isdir(com_path): | |
| get_all_path(path_list,com_path,filenmane_content) # 如果该路径是目录,则调用自身方法 | |
| elif os.path.isfile(com_path): | |
| if filenmane_content in com_path: | |
| path_list.append(com_path) # 如果该路径是文件,则追加到path_list中 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment