Rubrique précédente: ExistDir ou ExistDirectory – Vérifier si un répertoire existeRubrique suivante: FindClose : Fermer une opération Find


ExistFile – Déterminer si un fichier existe

Valide sur les plates-formes NetWare, Symbian OS, UNIX, Windows et Windows CE

La fonction ExistFile vérifie l'existence d'un fichier.

Format de la fonction :

ExistFile(filename as String) as Boolean
nom_fichier

Identifie le chemin du fichier.

Si le fichier existe, la fonction renvoie True ; dans le cas contraire, elle renvoie False.

Exemple :

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)
		quitter
	end if
	closeFile(rtr)
end if
	
section = "Section 1"
value = "Param_1 = Valeur_1" + LF + "Param_2 = Valeur_2"

if WriteIniSection( section, value, file) then
	Print("Réussite de WriteIniSection.")
else
	Print("Echec de WriteIniSection.")
endif

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

if WriteIniEntry( section, entry, value, file) then
	Print("Réussite de WriteIniFile.")
else
	Print("Echec de WriteIniFile.")
endif

section = "Section 1"
rtr = ReadIniSection(section, value, file)
if (rtr > 0) then
	Print( Str(rtr) + CR + LF + value)
else
	Print("Echec de ReadIniSection.")
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("Echec de ReadIniEntry.")

endif