diff --git a/zhconv.py b/zhconv.py index 9f9bd9b..c494249 100644 --- a/zhconv.py +++ b/zhconv.py @@ -30,7 +30,7 @@ def main(): if os.path.isfile(input_arg): target_dir = os.path.dirname(input_arg) - target_files = [input_arg] + target_files = [os.path.basename(input_arg)] elif os.path.isdir(input_arg): target_dir = input_arg target_files = None @@ -38,21 +38,21 @@ def main(): print(f"Error: Path '{input_arg}' does not exist.") return + os.chdir(target_dir) + if target_files is None: - target_files = glob.glob(os.path.join(target_dir, '*')) + target_files = glob.glob('*') converted_count = 0 - for file_path in target_files: - if not os.path.isfile(file_path): + for filename in target_files: + if not os.path.isfile(filename): continue - filename = os.path.basename(file_path) new_filename = convert_filename(filename, cc) if new_filename: - new_path = os.path.join(target_dir, new_filename) - if os.path.exists(new_path): + if os.path.exists(new_filename): print(f"Skipped (already exists): {new_filename}") else: - os.rename(file_path, new_path) + os.rename(filename, new_filename) print(f"Converted: {filename} -> {new_filename}") converted_count += 1