Merge pull request #568 from lededev/rmdir

rewrite rm_empty_folder, add option in config.ini
This commit is contained in:
Yoshiko2
2021-09-04 02:29:38 +08:00
committed by GitHub
3 changed files with 22 additions and 11 deletions

View File

@@ -72,14 +72,17 @@ def create_failed_folder(failed_folder):
def rm_empty_folder(path):
try:
files = os.listdir(path) # 获取路径下的子文件(夹)列表
except:
return
for file in files:
abspath = os.path.abspath(path)
deleted = set()
for current_dir, subdirs, files in os.walk(abspath, topdown=False):
try:
os.rmdir(os.path.join(path, file)) # 删除这个空文件夹
print('[+]Deleting empty folder', os.path.join(path, file))
still_has_subdirs = any(
_ for subdir in subdirs if os.path.join(current_dir, subdir) not in deleted
)
if not any(files) and not still_has_subdirs and not abspath == current_dir:
os.rmdir(current_dir)
deleted.add(current_dir)
print('[+]Deleting empty folder', current_dir)
except:
pass
@@ -195,9 +198,11 @@ if __name__ == '__main__':
print('[!] - ' + percentage + ' [' + str(count) + '/' + count_all + '] -')
create_data_and_move(movie_path, conf, conf.debug())
rm_empty_folder(conf.success_folder())
rm_empty_folder(conf.failed_folder())
rm_empty_folder(os.getcwd())
if conf.del_empty_folder():
rm_empty_folder(conf.success_folder())
rm_empty_folder(conf.failed_folder())
if len(folder_path):
rm_empty_folder(folder_path)
end_time = time.time()
total_time = end_time - start_time

View File

@@ -9,6 +9,7 @@ transalte_to_sc=0
multi_threading=1
;actor_gender value: female(♀) or male(♂) or both(♀ ♂) or all(♂ ♀ ⚧)
actor_gender=female
del_empty_folder=1
[proxy]
;proxytype: http or socks5 or socks5h switch: 0 1

View File

@@ -52,6 +52,8 @@ class Config:
return self.conf.getboolean("common", "transalte_to_sc")
def multi_threading(self) -> bool:
return self.conf.getboolean("common", "multi_threading")
def del_empty_folder(self) -> bool:
return self.conf.getboolean("common", "del_empty_folder")
def is_transalte(self) -> bool:
return self.conf.getboolean("transalte", "switch")
def is_trailer(self) -> bool:
@@ -168,6 +170,7 @@ class Config:
conf.set(sec1, "transalte_to_sc", "1")
# actor_gender value: female or male or both or all(含人妖)
conf.set(sec1, "actor_gender", "female")
conf.set(sec1, "del_empty_folder", "1")
sec2 = "proxy"
conf.add_section(sec2)
@@ -297,3 +300,5 @@ if __name__ == "__main__":
print(config.get_transalte_delay())
print(config.transalte_values())
print(config.actor_gender())
print(config.multi_threading())
print(config.del_empty_folder())