Home > other >  Please help to write a "according to the specified size, automatic filling file byte" code
Please help to write a "according to the specified size, automatic filling file byte" code

Time:02-22

For example, a file called triple-a. Dat file, the original size of 216 byte, hexadecimal below


I think I specified by a number of bytes, automatically complement 00
at the end of the fileFor example, by executing python XXX. Py aaa. Dat 256 this command
Aaa spontaneously. Dat this file data into the look of the below


Tail in aaa. Dat file, automatic filling 40 bytes (256-216), all is 00,
If the specified number of bytes (e.g., 256) in the sample orders less than or equal to the original file size, so after the execution of this command, file does not change,

Could you tell me how to write the code should be, please help!

CodePudding user response:

 
the import the OSS=int (input (" & gt; & gt;" ))

The file=r "c: \ aaa. Dat"
Size=OS. Path. Getsize (filename=file)
If the s & gt; Size:
With the open (file, 'ab +) as f:
G=b '\ x00' * (s - size)
F.w rite (g)
  • Related