FileExists ?
Posted: Thu Jan 08, 2009 1:02 am
I went back to work on a small project for a utility tonight. I needed some way to see if a file already exists in a directory and thought "Gee, I wish PB had a FileExists function of some type." I searched thru the forums but got frustrated with not really finding anything, just mentions from years gone by. I seem to remember mention of a library that had it but a whole library just for a one time use is a little much, so I kludged one up real quick to test with until I find something else. It looks like this:
Its called three times in the code and seems to work OK, but it is kinda ...well...it works anyway.
Anyone got anything better?
Code: Select all
Procedure.s FileExists(dir.s, ini.s)
If ExamineDirectory(0, dir, ini)
While NextDirectoryEntry(0)
file_exists$ = DirectoryEntryName(0)
Wend
FinishDirectory(0)
EndIf
ProcedureReturn file_exists$
EndProcedure
dir$ = "C:\test\"
ini$ = "test.ini"
If FileExists(dir$, ini$) = ""
MessageRequester("Information","File does not exist !"
Else
MessageRequester("Information","File exist !"
EndIf
Anyone got anything better?