Skip to content

Commit

Permalink
중복된 파일 발견시 다른 이름 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
SeoJueun committed Mar 19, 2021
1 parent afcdd91 commit 56fd4d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion text_cleaner_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from text_file_cleaner import TextFileCleaner
from text_filters import UUIDDashFilter, UUIDSearchFilter

APP_VERSION = '0.1.2'
APP_VERSION = '0.1.3'
DEBUG = False


Expand Down
17 changes: 17 additions & 0 deletions text_file_cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,27 @@ def get_total_file_lines(self):
def get_num_excluded(self):
return self._num_excluded

def get_suffixed_filename(self, path, index):
filename, file_extension = os.path.splitext(path)
if file_extension:
return '{}({}){}'.format(filename, index, file_extension)
else:
return '{}({}})'.format(filename, index)

def get_none_duplicated_path(self, path):
if not os.path.exists(path):
return path
for i in range(1, 100):
new_path = self.get_suffixed_filename(path, i)
if not os.path.exists(new_path):
return new_path
raise Exception("Too many duplicated files")

def process(self):
for path in self.path_list:
with csv_excel_reader(path) as in_file:
out_filename = self.add_prefix(path, 'cleaned_').replace('.xlsx', '.csv').replace('.xls', '.csv')
out_filename = self.get_none_duplicated_path(out_filename)
with open(out_filename, 'w', encoding='utf-8') as out_file:
for processed_lines in self.process_file(in_file, out_file):
yield processed_lines
Expand Down

0 comments on commit 56fd4d6

Please sign in to comment.