| """ |
| |
| A program to remove spaces from all files located in a specified input directory. |
| Written by Ye Kyaw Thu, LU Lab., Myanmar. |
| Last updated: 23 Jan 2024 |
| |
| Usage: |
| python ./rm_space.py --input ./syl_seg --output ./raw |
| |
| """ |
|
|
| import os |
| import argparse |
|
|
| def process_files(input_dir, output_dir): |
| |
| if not os.path.exists(output_dir): |
| os.makedirs(output_dir) |
|
|
| for filename in os.listdir(input_dir): |
| input_file_path = os.path.join(input_dir, filename) |
| output_file_path = os.path.join(output_dir, f"{filename}.raw") |
|
|
| |
| with open(input_file_path, 'r', encoding='utf-8') as file: |
| content = file.read().replace(' ', '') |
|
|
| |
| with open(output_file_path, 'w', encoding='utf-8') as file: |
| file.write(content) |
|
|
| print(f"Processed: {input_file_path} -> {output_file_path}") |
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser(description="Process files to remove spaces and save with .raw extension.") |
| parser.add_argument('--input', type=str, required=True, help="Input directory path") |
| parser.add_argument('--output', type=str, required=True, help="Output directory path") |
|
|
| args = parser.parse_args() |
|
|
| process_files(args.input, args.output) |
|
|
|
|