]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/FileUtils.py
Added the FileUtils module.
[dead/census-tools.git] / src / FileUtils.py
diff --git a/src/FileUtils.py b/src/FileUtils.py
new file mode 100644 (file)
index 0000000..2b89adf
--- /dev/null
@@ -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
+