import os import argparse from tqdm import tqdm def remove_commas(source_folder, target_folder): # Create target folder if it doesn't exist os.makedirs(target_folder, exist_ok=True) # Iterate over all txt files in the source folder for filename in os.listdir(source_folder): if filename.endswith(".txt"): # Open the source file and the target file with open(os.path.join(source_folder, filename), 'r') as source_file, \ open(os.path.join(target_folder, filename), 'w') as target_file: # Read each line from the source file for line in tqdm(source_file): # Replace commas with nothing line_without_commas = line.replace(',', ' ') # Write the new line to the target file target_file.write(line_without_commas) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--source_folder", help="Folder with files that contain commas") parser.add_argument("--target_folder", help="Folder with files that don't contain commas") args = parser.parse_args() remove_commas(args.source_folder, args.target_folder) print(f"Files without commas are saved in : {args.target_folder}")