Home > other >  Please help to write a code file segmentation, demand is not the same as the file size
Please help to write a code file segmentation, demand is not the same as the file size

Time:11-14

There is now a XXX. Bin file, the size of 7221 bytes, I think I specified according to the file name and the number of bytes, will split it into several small files,

Which is based on a list to XXX. Bin file data from beginning to end, in turn, according to the specified number of bytes segmentation, list format is as follows (the front for the file name after segmentation, the back of the values for the number of bytes of the file size)
Aa1. Bin 230
Aa2. Bin 5900
Bb2. Bin 128
Cc. Bin 963

CodePudding user response:

I don't know if you want, reference,
 files=[(aa1. Bin, 230), (' aa2. Bin, 5900), (' bb2. Bin, 128), (936) 'cc. Bin,] 
With the open (' XXX. Bin) as binfile:
Contents=binfile. Read ()
File_bytes=sum ([file [1] for file files in])
Assert (file_bytes & lt;=len (contents))

Start=0
For afile in files:
End=start + afile [1]
The content=contents [start: end]
Start=end
With the open (afile [0], 'w') as newfile:
Newfile. Write (content)
  • Related