Last active
July 19, 2024 20:25
-
-
Save TheExpertNoob/f2d0145f7dabfd42d227134cb39172e6 to your computer and use it in GitHub Desktop.
Simple python split for fat32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def split_file(input_file, chunk_size, output_folder): | |
# Create a folder for the split files | |
base_name = os.path.splitext(os.path.basename(input_file))[0] | |
ext_name = os.path.splitext(os.path.basename(input_file))[1] | |
output_folder_name = os.path.join(output_folder, f'{base_name}_split{ext_name}') | |
os.makedirs(output_folder_name, exist_ok=True) | |
# Open the input file | |
with open(input_file, 'rb') as f_in: | |
part_num = 0 | |
while True: | |
# Read chunk_size bytes from the input file | |
chunk = f_in.read(chunk_size) | |
if not chunk: | |
break | |
# Write the chunk to a numbered output file | |
output_file = os.path.join(output_folder_name, f'{part_num:02}') | |
with open(output_file, 'wb') as f_out: | |
f_out.write(chunk) | |
part_num += 1 | |
def set_archive_bit(folder): | |
# Set the archive bit on the folder | |
try: | |
import ctypes | |
# 0x10000 is the archive attribute constant for Windows | |
ctypes.windll.kernel32.SetFileAttributesW(folder, 0x10000) | |
except Exception as e: | |
print(f"Failed to set archive bit: {e}") | |
def main(): | |
if len(sys.argv) != 2: | |
print("Usage: python split.py <input_file>") | |
return | |
input_file = sys.argv[1] | |
chunk_size = (4 * 1024 * 1024 * 1024) - 1 # 4 GB chunk size minus 1 byte (adjust as needed) | |
output_folder = '.' # Output folder is the current directory | |
split_file(input_file, chunk_size, output_folder) | |
set_archive_bit(output_folder) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment