Qbasicnews.com

Full Version: Files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
for example lets say i was making a file copier. How do i open a file. get input from it then print to another file?

File1:
Hi
Bob

File2:
Hi
Bob

I tryed some things but none worked. [Image: KkatSad.txt]

post 198
the easy way is to shell to dos and use the dos copy command.

within QB, the best way depends on your data-type. If you can't count on formatting (deliminated data or line breaks) then you can use something like the following.

Code:
PRINT "Input a string to place at the front of :", filein$
INPUT frontstring$

OPEN filein$ FOR BINARY AS #1
OPEN fileout$ FOR BINARY AS #2

PUT #2, , frontstring$

DO UNTIL EOF(1)
  GET #1, , datachunk&
  PUT #2, , datachunk&
LOOP

CLOSE #1
CLOSE #2
what if i want to read from file 1 add a string to the front of it then put it in file 2?
Quote:what if i want to read from file 1 add a string to the front of it then put it in file 2?

You are kidding, right???

OK...I'll edit my last post to show you...
ok...
wait that doesn't work. i want it at the begining of everyline. and when i do that it is all mess up.
Quote:i want it at the begining of everyline. and when i do that it is all mess up.

Every line??? that's why I said the method you use depends on what kind of data the file contains. You should open the file in one of the text modes then and use LINE INPUT

Look up the following keywords that pertain to file I/O

OPEN
CLOSE

INPUT
OUTPUT
APPEND
RANDOM
BINARY

WRITE
GET
PUT

What you want to do is read a line of data into a string, then prepend the string with your string, then write the result to the file.
thanks it works!
[Image: KkatBigGrin.txt]