|
@@ -304,3 +304,16 @@ def write_page(path: str, code: str):
|
|
utils.mkdir(os.path.dirname(path))
|
|
utils.mkdir(os.path.dirname(path))
|
|
with open(path, "w") as f:
|
|
with open(path, "w") as f:
|
|
f.write(code)
|
|
f.write(code)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def empty_dir(path, keep_files=[]):
|
|
|
|
+ """Remove all files and folders in a directory except for the kept file- or foldernames.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ path (str): The path to the directory that will be emptied
|
|
|
|
+ keep_files (list, optional): List of filenames or foldernames that will not be deleted. Defaults to [].
|
|
|
|
+ """
|
|
|
|
+ directory_contents = os.listdir(path)
|
|
|
|
+ for element in directory_contents:
|
|
|
|
+ if element not in keep_files:
|
|
|
|
+ utils.rm(os.path.join(path, element))
|