myZagar / tool /rm_space.py
ye-nlp's picture
added tool/ folder
ff6f281
"""
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):
# Create output directory if it doesn't exist
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")
# Read the content and remove spaces
with open(input_file_path, 'r', encoding='utf-8') as file:
content = file.read().replace(' ', '')
# Write the content to the new file in the output directory
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)