Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OPEN file routine adding extra "0" to output file.
#11
Quote:Or couldnt you just swap the GET and PUT statements? Wink

But wouldn't that cause the first run through the loop to PUT a zero at the beginning, rather than the end of the file? Their wouldn't be any data in a$ yet, and the two files need to end up being identical.
Reply
#12
Yea... I realised after I posted =P

but how about

Code:
CLS
file1$ = "C:\filetest.001"
file2$ = "C:\filetest.002"
a$ = CHR$(32)
count = 0
OPEN file1$ FOR BINARY AS #1
OPEN file2$ FOR BINARY AS #2
  DO UNTIL EOF(1)
    IF count THEN PUT #2, count, a$
    count = count + 1
    GET #1, count, a$
  LOOP
CLOSE
SYSTEM

I havent tested but i reckon it would work?
Reply
#13
Code:
SUB copy (f1$, f2$)
   f1% = FREEFILE
   OPEN f1$ FOR BINARY AS #f1%
   f2% = FREEFILE
   OPEN f2$ FOR BINARY AS #f2%
   WHILE NOT EOF(f1%)
      buffer$ = INPUT$(16384, f1%)
      PUT #f2%, , buffer$
   WEND
   CLOSE f1%, f2%
END SUB
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#14
Yes..I was about to post about that method. File copying is faster when you copy in chunks. :wink:
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#15
Thanks Nathan for reminding me about using a buffer.
It worked perfectly, (and fast).

Let me ask one more thing related to this.

If I know ahead of time that my file will always be smaller than
16k, can I skip the WHILE . . . WEND loop, and just do a direct:

Code:
OPEN f1$ FOR BINARY AS #1
OPEN f2$ FOR BINARY AS #2
   buffer$ = INPUT$(16384, 1)
   PUT #2, , buffer$
CLOSE #1, #2

BTW - I tested that code, and it seems to work, just wondering if there were any negative reasons to doing it that way. Wink

Dex
Reply
#16
The only negative thing about using a buffer is that when you'r code increase in size the buffer MIGHT generate a "out of memory" error.

I abuffer of 4096 is usually enough. And you won't run out of memory as soon.

Then again, as long as it works, go with it =)
Reply
#17
If you try to get a chunk that is larger than the file itself, that's fine - it won't crash, and it will be just as if you got a properly-sized, small enough chunk. So no problems should occur with this:
Code:
OPEN "file1.dat" FOR BINARY AS #1
OPEN "file2.dat" FOR BINARY AS #2
DO
   buffer$=INPUT$(16384,#1)
   IF EOF(1) THEN EXIT DO
   PUT #2,buffer$
LOOP
CLOSE #1,#2
That will work, I believe, even if file1.dat is 10 bytes.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#18
Thanks, Smile

This is part of a small utility I'm writing that modifies the AUTOEXEC.BAT file, so, 4096 should work fine. (Or maybe 8192)

I can't imagine anyone having an AUTOEXEC.BAT file larger than that. (Although, its possible.) Wink

Dex
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)