Skip to content

Instantly share code, notes, and snippets.

@friskfly
Created December 27, 2012 12:41
Show Gist options
  • Save friskfly/4388107 to your computer and use it in GitHub Desktop.
Save friskfly/4388107 to your computer and use it in GitHub Desktop.
python findFile(folders,file_name) 在所有目录列表中查找是否存在文件 存在则返回所在目录
# 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