Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Copy And Rename Files Using Free Basic
#21
I suddenly feel very... objectified..
Reply
#22
I saw a hand held computer called "zire" at Radio Shack... For a second, I thought I was in a 3D forum.. :o .. But then I noticed, it was spelled Z-I-R-E, not Z-!-R-E... Tongue
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#23
[Image: zire_front.jpg]Palm Zire
Reply
#24
I'm so famous they named a Palm after me.. kind of old news though Tongue
Reply
#25
Yeah.. I don't get out much.. just saw it last week or so.. Tongue
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#26
Quote:.....Here's some code:
Code:
const bufferSize = 1024
old$ = "\old_folder\old_name.blah"
new$ = "\new_folder\new_name.blah"

' If new$ exists, delete it:
if len(dir$(new$)) then kill new$

open old$ for binary access read as #1
open new$ for binary access write as #2

' Assuming FB's input$ works like QB's, and assuming
' FB's put has no chr$(0) trouble, this should work:
do
   buffer$ = input$(bufferSize, #1)
   put #2, , buffer$
loop until len(buffer$) < bufferSize

close #1, #2

EDIT: Method #2 2.0 - the "I forgot filenames can have spaces" release:
Code:
#ifdef __FB_LINUX__
const copyCommand = "cp"
#else
const copyCommand = "copy"
#endif

shell copyCommand + " " + chr$(34) + old$ + chr$(34) + " " + chr$(34) + new$ + chr$(34)

I've had bad experiences copying files from within a QB program by reading the first file and writing to the second. Opening the files for binary helps most of the time.

But, if the file is foreign to you, that is, you didn't create it, you could run into the following problems:
1) Non-standard end-of-record delimiters. (ok if open binary)
2) chr$(0) versus chr$(255) problems.
3) No end of record delimiters at all, which could cause input buffer overflow. (ok if open binary)
4) A zero-length-file which will probably cause an error on input.

All of the above problems go away if you SHELL to a COPY or MOVE command.

Also, if the input file does not exist, the COPY or MOVE will flash an error and continue, which may be good or bad for you. If your program opens the non-existant file, it hangs up on the error.
*****
Reply
#27
thanks benedicto for that solution.
i put this in the right section... wtf arpgme?
Reply
#28
Code:
open file1$ for binary as #1
ll = lof(1)
redim fbuff(ll-1) as ubyte
get #1, 1, fbuff()
close #1

kill file2$
open file2$ for binary as #1
put #1, 1, fbuff()
close #1
redim fbuff(0) as ubyte
Enjoy
Reply
#29
"Enjoy"
thanks, i will.

by the way, fieldview is looking hot. 8)
Reply
#30
heh, thanks.. if we could only finish it so people could see how hot it really is Tongue
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)