From b006aee34d1382e3494b6e94d4e2156e80ead7c9 Mon Sep 17 00:00:00 2001 From: lededev Date: Sun, 17 Oct 2021 21:21:12 +0800 Subject: [PATCH] failed_list.txt keep order remove duplication --- AV_Data_Capture.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/AV_Data_Capture.py b/AV_Data_Capture.py index 9ae551b..d9c54b2 100755 --- a/AV_Data_Capture.py +++ b/AV_Data_Capture.py @@ -252,14 +252,14 @@ def movie_lists(source_folder, regexstr): failed_set = set() if (main_mode == 3 or soft_link) and not conf.ignore_failed_list(): try: - with open(failed_list_txt_path, 'r', encoding='utf-8') as flt: - flist = flt.read().splitlines() - failed_set = set(flist) - if len(flist) != len(failed_set): - with open(failed_list_txt_path, 'w', encoding='utf-8') as flt: - wtlines = [line + '\n' for line in failed_set] - wtlines.sort() - flt.writelines(wtlines) + flist = failed_list_txt_path.read_text(encoding='utf-8').splitlines() + failed_set = set(flist) + if len(flist) != len(failed_set): # 检查去重并写回,但是不改变failed_list.txt内条目的先后次序,重复的只保留最后的 + fset = failed_set.copy() + for i in range(len(flist)-1, -1, -1): + fset.remove(flist[i]) if flist[i] in fset else flist.pop(i) + failed_list_txt_path.write_text('\n'.join(flist) + '\n', encoding='utf-8') + assert len(fset) == 0 and len(flist) == len(failed_set) except: pass if not Path(source_folder).is_dir():