Created
November 5, 2012 04:37
-
-
Save jbranchaud/4015348 to your computer and use it in GitHub Desktop.
A quick and tolerant directory validator for unix systems in Python
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
import os | |
""" | |
validate_directory: string -> string | |
given a string that represents a directory, this function will go through and | |
do some basic validation on it. If there is a problem with the directory as | |
given, it will be converted to the home directory and returned as is. | |
""" | |
def validate_directory(directory=None): | |
if directory == None or directory == '~' or not os.path.isdir(directory): | |
# if there is a problem, the default is the home directory | |
return os.path.expanduser('~') | |
return os.path.abspath(directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment