From: Michael Orlitzky Date: Wed, 7 Oct 2009 14:58:13 +0000 (-0400) Subject: Added the FileUtils module. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fcensus-tools.git;a=commitdiff_plain;h=11f2b70a38c7a8dbed276cd420a94e0e24bd3084 Added the FileUtils module. --- diff --git a/src/FileUtils.py b/src/FileUtils.py new file mode 100644 index 0000000..2b89adf --- /dev/null +++ b/src/FileUtils.py @@ -0,0 +1,29 @@ +""" +Utility functions for working with the filesystem, generally modeled +after useful shell commands. +""" + +import os + + +def rm_f(path): + """ + Remove (unlink) a file, ignoring any exceptions that may be + thrown. + """ + try: + os.remove(path) + except: + pass + + +def mkdir_p(path, mode): + """ + Create a directory hierarchy, ignoring any exceptions that may be + thrown. + """ + try: + os.makedirs(path, mode) + except: + pass +