def cleanDirectory(directory): CraftCore.log.debug("clean directory %s" % directory) if (os.path.exists(directory)): for root, dirs, files in os.walk(directory, topdown=False): for name in files: if not OsUtils.rm(os.path.join(root, name), True): CraftCore.log.critical("couldn't delete file %s\n ( %s )" % (name, os.path.join(root, name))) for name in dirs: if not OsUtils.rmDir(os.path.join(root, name), True): CraftCore.log.critical("couldn't delete directory %s\n( %s )" % (name, os.path.join(root, name))) else: os.makedirs(directory)
def cleanDirectory(directory): CraftCore.log.debug("clean directory %s" % directory) if os.path.exists(directory): # don't delete containg directrory as it might be a symlink and replacing it with a folder # breaks the behaviour with os.scandir(directory) as scan: for f in scan: if f.is_dir(): if not OsUtils.rmDir(f.path, force=True): return False else: if not OsUtils.rm(f.path, force=True): return False return True else: return createDir(directory)
def test_rmDir(self): dirName = tempfile.mkdtemp() OsUtils.rmDir(dirName)