This is a simple but very interesting lib to know if one file is opened by other program.
Well, i need this to know when an external program finish job with a file. Is nice if you are waiting for other programs.
I was looking for other ways to know it, reading size, and others but no work i spect. If some body know other ways to do this im very interested to learn how.
Enjoy it!.. PBforum the best forum!
feel free to improve or modify..
Code: Select all
; -------------------------------------------------------------
; -------------------------------------------------------------
;
; lib name: IsFileOpen
; code by : minimy
; date : 2019.10.05
; O.S. : Multi (not tested..) tell me about please :)
; CPU : x86, x64
; info : check if file is open by other program
; syntax : check= IsFileOpen(mifile.s)
; return : 1 if file is open by other program, 0 if is not opened
;
; garanty : three steps ;-)
; worktime: two beers.. __.oO
;
; -------------------------------------------------------------
; -------------------------------------------------------------
Procedure IsFileOpen(filename.s)
Protected.i file= OpenFile(#PB_Any,filename,#PB_File_Append)
If file
CloseFile(file)
ProcedureReturn #False
Else
ProcedureReturn #True
EndIf
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
CompilerIf #PB_Compiler_Processor= #PB_Processor_x86
softname.s= "IsFileOpen() [x86]"
CompilerElse
softname.s= "IsFileOpen() [x64]"
CompilerEndIf
;start check
mifile.s= "C:\Users\Usuario\Desktop\Proy\TEST\test.txt"
CreateFile(0,mifile)
WriteStringN(0,"wtf?")
Debug IsFileOpen(mifile) ;check if file is open by other program
MessageRequester(softname,"File must be open by CreateFile(0,mifile) or other external program. Then return 1")
CloseFile(0)
Debug IsFileOpen(mifile)
MessageRequester(softname,"File was closed. Now return 0")
CompilerEndIf
Evolution?
Ice age, stone age, iron age, bronze age, industrial age, modern, age, stupidity age..