Previous Topic: ExistDir or ExistDirectory - Check if a Directory ExistsNext Topic: FindClose - Close a Find Operation


ExistFile - Check if a File Exists

Valid on NetWare, Symbian OS, UNIX, Windows and Windows CE

The ExistFile function checks for the existence of a file.

This file content function has the format:

ExistFile(filename as String) as Boolean
filename

Identifies the file path.

If the file exists, the function returns TRUE; otherwise, it returns FALSE.

Example: ExistFile function

Dim file, section, entry, value as string

Dim LF, CR as char
Dim rtr as integer

ClrScr()
LF = 0x0a
CR = 0x0d
file = "c:\dmscript.ini"
if Not(ExistFile(file)) then
	rtr = CreateFile(file, O_TEXT)
	if rtr = -1 then
		SetStatus(1)
		exit
	end if
	closeFile(rtr)
end if
	
section = "Section 1"
value = "Param_1 = Wert_1" + LF + "Param_2 = Wert_2"

if WriteIniSection( section, value, file) then
	Print("WriteIniSection successfully completed.")
else
	Print("WriteIniSection failed.")
endif

section = "Section 2"
entry = "Param_3"
value = "Wert_3"

if WriteIniEntry( section, entry, value, file) then
	Print("WriteIniFile successfully completed.")
else
	Print("WriteIniFile failed.")
endif

section = "Section 1"
rtr = ReadIniSection(section, value, file)
if (rtr > 0) then
	Print( Str(rtr) + CR + LF + value)
else
	Print("ReadIniSection failed.")
endif

section = "Section 2"
entry = "Param_3"
rtr = ReadIniEntry(section, entry, value, file)

if (rtr > 0) then
	Print( Str(rtr) + CR + LF + entry + " = " + value)
else
	Print("ReadIniEntry failed.")

endif