There is not many
things to do for verifying if a file exists or not, you can :
Search for it with the
FindFirstFile function,
Try to open it with
CreateFile,
The simpliest way is to call the
PathFileExists function which returns TRUE if the file exists and FALSE
if it does not exist.
Here is an example of what such a function could be :
DoesThisFileExist PROC USES
EDI,__lpszFileName:LPSTR
mov
edi,__lpszFileName
test edi,edi ;
The pointer is NULL
jz @Error_1
INVOKE
lstrlen,edi
; Is the file name empty
test eax,eax
jz @Error_2
INVOKE PathFileExists,edi
mov edx,TRUE
jmp @Exit
@Error_1 :
mov edx,-1
; The file name pointer is NULL
mov eax,edi
jmp @Exit
@Error_2 : mov
edx,-2
; The file name is empty
@Exit :
test eax,eax
ret
DoesThisFileExist ENDP
This function returns TRUE if the file exists
and FALSE if not.
If the function fails, EAX is set to ZERO and EDX receives the TRUE value or a
negatve number.
If EDX has the TRUE value, that means that the PathFileExists function could
not find the specified file, in that case EAX is FALSE.
If EDX has a negative value, that means that the file name is not valid. When
this kind of error is met, EAX is FALSE.
If EDX = -1 => The pointer to the file name is NULL.
if EDX = -2 => The file name is empty (The first caracter is ZERO).
At the end of the function the ZERO flag is set if an error occured.
INVOKE DoesThisFileExist,ADDR _szMyFileName
jz @Error
<Return>