
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM |
DISK I/O
Detect if a file is busy
I use the following routine. Note that some apps (like BBEdit) don't actually hold a file open.
CLEAR LOCAL
DIM osErr%
DIM pBlock.128
LOCAL FN IsFileOpenOrLocked(SourceFile$,SourceVolRef%,IsOpen&,IsLocked&)
LONG IF LEN(SourceFile$) > 0
pbPtr& = @pBlock
pbPtr&.ioCompletion& = 0
pbPtr&.ioNamePtr& = @SourceFile$
pbPtr&.ioVRefNum% = SourceVolRef%
pbPtr&.ioFDirIndex% = 0
osErr% = FN GETFILEINFO (pbPtr&)
LONG IF osErr% = _noErr
AttribByte% = PEEK(pbPtr&+_Ioflattrib)
LONG IF IsOpen& > 0
Answer% = _False
IF (AttribByte% AND BIT(7)) THEN Answer% = _True
POKE WORD IsOpen&,Answer%
END IF
LONG IF IsLocked& > 0
Answer% = _False
IF (AttribByte% AND BIT(0)) THEN Answer% = _True
POKE WORD IsLocked&,Answer%
END IF
END IF
END IF
END FN = osErr%
WINDOW 1,"IsFileOpenOrLocked Test",(0,0)-(400,400),_Doc_NoGoAway
TEXT _Monaco,9,0,0
osErr% = FN IsFileOpenOrLocked("fred.txt",0,@isitOpen%,@isitLocked%)
PRINT "isitOpen%: ";isitOpen%
PRINT "isitLocked%: ";isitLocked%
PRINT
DO
HANDLEEVENTS
UNTIL gUserQuits%
END
|