Announcement

Collapse
No announcement yet.

file open

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Steve Bouffe
    replied
    Just read the manual !



    ------------------

    Leave a comment:


  • Steve Bouffe
    replied
    Alan,

    How would you stop another process from reading the file :-

    Open "b",#1,"file.dat"
    Lock #1
    close#1

    If one process opened the file and before the lock command, another process opened the same file.

    How could you stop this ?


    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Thanks to Steve Bouffe, Alan Earnshaw and Michael Mattias for
    your quick replay.

    Pat

    ------------------

    Leave a comment:


  • Michael Mattias
    replied
    FREEFILE does not return a "DOS" channel - it returns an "application" channel. (I think under PB/DOS, it often happens to be the DOS handle).

    FREEFILE will not fail if too many files are open; however, the OPEN will fail on, BION, "too many files" (error 67).

    Totally unsolicited: if/when you move to Windows programming, or if MS-DOS changes again, the habit of not "hardcoding" file handles will save you a ton of work in the future. Better to stick with FREEFILE and a dataname. To use the handle across procedures, I like to pass handles: a handle of zero means the file is not open and I have to openj it, e.g....

    [code]
    SUB Foo (H AS INTEGER)
    IF H = 0 THEN
    H = FREEFILE
    OPEN "thefile" FOR RANDOM AS H LEN=whatever
    END IF
    ....
    ,,,,
    GET #H,RecordNo,Dataname...

    END SUB
    [code]

    MCM




    MCM

    Leave a comment:


  • Alan Earnshaw
    replied
    Pat,

    To determine if a file handle is open, use FILEATTR(HandleNum%, 0). (It returns true if the handle is open.)

    However, you do not have to use sequential handle numbers. You can use 308 if you like, so checking all numbers from 1 - 32767 will take a significant amount of time.

    As far as available file handles, I do not know of any way to determine how many file handles are available to an application. You can make a simple function call to allocate more file handles to your program (see DOSUNIT for the routine), so even if you know there are 15 in use, it does not mean there are none left.

    I think the best solution is to encapsulate your code in a procedure or function with a local error trap.

    Side note to Steve Bouffe: As long as SHARE is loaded (under DOS; it's built into Windows 95+), you can open the same file multiple times with no errors. To prevent other processed from opening the file, you must explicitly add the LOCK parameter to the OPEN statement.

    Alan


    ------------------
    Alan C. Earnshaw
    Information Management Systems, Inc.
    http://www.infoms.com

    Leave a comment:


  • Steve Bouffe
    replied
    Perhaps you could use a binary file

    "00000000000000000000"

    Just open the file and look for the first "0", use the position for the file handle and chage it to a "1"

    When you have done with the file, change the "1" back to a "0"

    As binary files can only by opened by one process, multiple routines can use it on a first come, first served basis.

    You may need to implement some sort of error trap routine to see if the file is in use, wait a second and try again.

    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest started a topic file open

    file open

    Can anyone tell me how to determine which DOS channels are available to use, that is, not in use, other than FREEFILE?
    Suppose an application has already used 14 DOS-channels. Won't
    FREEFILE fail? Then how can I save things to disk without opening/closing another file? And if I did, can I save the name of the file whose DOS channel I just used so that I can then re-open it?

    Thanks.

    Pat
Working...
X