Last active
April 5, 2016 09:37
-
-
Save yeyuguo/cb3a0724ec75109f1c2e301830ae32ed to your computer and use it in GitHub Desktop.
找到目录中的最后一个文件
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
| def search_index_file(search_dir=None,index=None): | |
| if search_dir is None: | |
| search_dir = '/' | |
| print(search_dir) | |
| result = search_dir | |
| if index is not None: | |
| index = int(index) | |
| dirs = sorted(os.listdir(search_dir))[index] | |
| path_file = os.path.join(search_dir,dirs) | |
| if os.path.isdir(path_file): | |
| result=search_index_file(search_dir=path_file,index=index) | |
| else: | |
| result = path_file | |
| #这里的return很有意义,第二次进入search_index_file的return result是 找到文件的else返回的结果 | |
| #该结果给第一次执行search_index_file的if os.path.isdir(path_file)的result, | |
| # 这时候第二次执行return result就是整个最终的结果 | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment