Created
December 27, 2012 12:41
-
-
Save friskfly/4388107 to your computer and use it in GitHub Desktop.
python findFile(folders,file_name) 在所有目录列表中查找是否存在文件 存在则返回所在目录
This file contains 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
# Finds a real file path among given folder paths | |
# and returns the path or None | |
# | |
# @type folders: list<string> | |
# @param folders: list of paths to folders to look into | |
# @type file_name: string | |
# @param file_name: file name to search | |
# | |
# @return string file path or None | |
def findFile(folders, file_name): | |
if folders is None: | |
return None | |
for folder in folders: | |
if os.path.exists(os.path.join(folder, file_name)) is True: | |
return folder | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment