QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 Return to Index  

Function to Test for the Existence of a File

December 14 2001 at 2:20 PM
Earthborn  (Premier Login iorr5t)
Forum Owner

FAQ013 = How can I test for the existence of a file?

cls
do
  input "File";f$: if f$="" then system
  if FileExist(f$) then print "Exists" else print "No such file"
loop
system

FUNCTION FileExist(Filename$)
Rem by Earthborn
temp$ = ENVIRON$("TEMP")
IF temp$="" THEN temp$="C:"
SHELL "if exist " + Filename$ + " echo -1>" + temp$ + "\temp.txt"
a = FREEFILE
OPEN temp$ + "\temp.txt" FOR INPUT AS #a
IF LOF(a) <> 0 THEN INPUT #a, a$ ELSE a$ = "0"
CLOSE #a
KILL temp$ + "\temp.txt"
FileExist = VAL(a$)
END FUNCTION


    
This message has been edited by iorr5t on Nov 22, 2003 5:49 PM
This message has been edited by iorr5t on Nov 21, 2003 12:02 PM


 
 Respond to this message   
Responses