- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to spilt a binary file into multiple files using Python?
To split a big binary file in multiple files, you should first read the file by the size of chunk you want to create, then write that chunk to a file, read the next chunk and repeat until you reach the end of original file.
For example, you have a file called my_song.mp3 and want to split it in files of size 500 bytes each.
CHUNK_SIZE = 500 file_number = 1 with open('my_song.mp3') as f: chunk = f.read(CHUNK_SIZE) while chunk: with open('my_song_part_' + str(file_number)) as chunk_file: chunk_file.write(chunk) file_number += 1 chunk = f.read(CHUNK_SIZE)
In your current directory, now you'll find chunks of your original file scattered across multiple files with prefix as: my_song_part_
- How to merge multiple files into a new file using Python?
- How to concatenate two files into a new file using Python?
- How to open multiple files using a File Chooser in JavaFX?
- Python - Write multiple files data to master file
- How we can split Python class into multiple files?
- Rename multiple files using Python
- How to rename multiple files recursively using Python?
- How are files added to a tar file using Python?
- How are files added to a zip file using Python?
- How to write binary data to a file using Python?
- How to Merge multiple CSV Files into a single Pandas dataframe ?
- Merge contents of two files into a third file using C
- How are files extracted from a tar file using Python?
- Java program to merge two files into a third file
- Python Pandas- Create multiple CSV files from existing CSV file