Create a new file...diff path

New question...my program will run from a cd-rom with external data files read from the cd. My problem is I want to create or move a file to the users hard drive to keep a log file. Can qbasic move files to a new location and write to them? Thanks.


Comments

  • In Visual Basic there is a function called "FileCopy", if you don't have if, write your own.

    [code]
    source = "d:main.log"
    dest = "c:MyProgmain.log"
    open source for binary as inf
    open dest for binaty as outf

    do while not eof(inf)

    loop
    close inf, outf
    [/code]

    after "do while ..." you have to write yourself, read from the source and write to dest (using put and get commands)

  • While Qbasic only has limited file functions of its own, it does have the SHELL command which executes any DOS command. Through SHELL you could use DOS's COPY command, like so:

    Shell "Copy D:frompathfromfile.ext C: opath"

    I don't know if you know anything about DOS, but i'll explain it in case not:

    DOS, unlike windows, does everything via typed commands. To talk about file access in dos, you refer to them by 'paths', similar to an internet address: Htpp://....whatever.
    The copy command passed to DOS here by the shell command is saying "Look in D (ususally the DOS letter assigned to the CD, but it may not be, so make sure first) then look in the folder called 'frompath' (or any other folder name you want) and find the file named fromfile.ext (again.. any file will do, just an example). Then copy it to C (ususally the letter assigned to the harddrive) and put it in the folder (path) called 'topath'."

    Then once the file is copied to the new location, you can refer to it in your OPEN command instead of the one on the CD.


    : New question...my program will run from a cd-rom with external data files read from the cd. My problem is I want to create or move a file to the users hard drive to keep a log file. Can qbasic move files to a new location and write to them? Thanks.
    :
  • In addition to this, you may also want to examine DOS's IF and ERRORLEVEL statements as well. DOS sets an error condition in ERRORLEVEL if the copy / move fails... this condition can be mirrored to an environment variable, which can then be looked at by your program and acted upon accordingly.


    : While Qbasic only has limited file functions of its own, it does have the SHELL command which executes any DOS command. Through SHELL you could use DOS's COPY command, like so:
    :
    : Shell "Copy D:frompathfromfile.ext C: opath"
    :
    : I don't know if you know anything about DOS, but i'll explain it in case not:
    :
    : DOS, unlike windows, does everything via typed commands. To talk about file access in dos, you refer to them by 'paths', similar to an internet address: Htpp://....whatever.
    : The copy command passed to DOS here by the shell command is saying "Look in D (ususally the DOS letter assigned to the CD, but it may not be, so make sure first) then look in the folder called 'frompath' (or any other folder name you want) and find the file named fromfile.ext (again.. any file will do, just an example). Then copy it to C (ususally the letter assigned to the harddrive) and put it in the folder (path) called 'topath'."
    :
    : Then once the file is copied to the new location, you can refer to it in your OPEN command instead of the one on the CD.
    :
    :
    : : New question...my program will run from a cd-rom with external data files read from the cd. My problem is I want to create or move a file to the users hard drive to keep a log file. Can qbasic move files to a new location and write to them? Thanks.
    : :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories