|
@@ -0,0 +1,50 @@
|
|
|
+import os
|
|
|
+import time
|
|
|
+
|
|
|
+files = []
|
|
|
+
|
|
|
+
|
|
|
+class FileUtil:
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def mkdir_folder(path):
|
|
|
+ if os.path.exists(path):
|
|
|
+ print('folder exists')
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ print('create folder')
|
|
|
+ os.mkdir(path)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def load_file(path):
|
|
|
+ for file in os.listdir(path):
|
|
|
+ file_path = os.path.join(path, file)
|
|
|
+ if os.path.isdir(file_path):
|
|
|
+ FileUtil.load_file(file_path)
|
|
|
+ else:
|
|
|
+ files.append(file_path)
|
|
|
+ return files
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def remove_files(breday, path):
|
|
|
+ bretime = time.time() - 3600 * 24 * breday
|
|
|
+
|
|
|
+ for file in FileUtil.load_file(path):
|
|
|
+ filename = file
|
|
|
+ if os.path.getmtime(filename) < bretime:
|
|
|
+ try:
|
|
|
+ if os.path.isfile(filename):
|
|
|
+ os.remove(filename)
|
|
|
+ elif os.path.isdir(filename):
|
|
|
+ os.removedirs(filename)
|
|
|
+ else:
|
|
|
+ os.remove(filename)
|
|
|
+ print("%s remove success." % filename)
|
|
|
+ except Exception as error:
|
|
|
+ print(error)
|
|
|
+ print("%s remove faild." % filename)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ file_path = r'D:\elab-code\elab-layout-engine\resources\house_type\house_dxf_files'
|
|
|
+
|