Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def split_files(baseFilename):
- # Define the file extensions and corresponding output file names
- extensions = {'.c': 'c_', '.cpp': 'cpp_', '.cs': 'cs_'}
- # Create output files for each extension type
- output_files = {}
- for extension, prefix in extensions.items():
- output_filename = f"{prefix}{baseFilename}.txt"
- output_files[extension] = open(output_filename, 'w')
- # Read and process the input file
- with open(baseFilename, 'r') as input_file:
- current_extension = None
- for line in input_file:
- line = line.strip()
- if line.endswith(tuple(extensions.keys())):
- current_extension = line[line.rfind('.'):].lower()
- elif current_extension:
- output_files[current_extension].write(line + '\n')
- # Close all output files
- for file in output_files.values():
- file.close()
- # Example usage
- baseFilename = "file_00.txt"
- split_files(baseFilename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement