-
Dear all,
Making a program to copy a file to another file but only the specified range of bytes. IE: The first 4500k of a 10mb file etc... I've fiddled with some code, works fine, but rus extremely slow, im talking, 5 minutes to copy 1000k of data, anyone know of a more efficient way to copy a file using byte range, here's my code...
Code:
Dim TempChar as Byte
Dim ByteLength as Long
Open "input.dat" for Binary Access Read as #1
Open "output.dat" for Binary Access Write as #2
ByteLength = 4539139 'End of file or byte length, just over 4.5mb of the file
'from start of file to end of marker/byte length...
For x = 1 to ByteLength
Get #1,, TempChar
Put #2,, TempChar
Next x
Close #1
Close #2
Anyone know why it takes so god damn long to do something simple? its using on average of %6 CPU usage the rest is idle, therefore it aint the CPU causing probs. please help!
-
it is slow because the string is very long. speed is not directly relative to string length, try using several smaller strings, not more than 3000 characters at a time.
-
Ok, loading a varlen string is much faster, aslo use freefile so that you don't get invalid filenumbers
Code:
Dim Temp as string
Dim ByteLength as Long
f1=freefile
Open "input.dat" for Binary Access Read as f1
f2=freefile
Open "output.dat" for Binary Access Write as f2
Get f1,, Temp
Put f2,, Temp
Close f1
Close f2