The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: skywalker on February 13, 2005, 03:06:05 PM

Title: Structure help needed
Post by: skywalker on February 13, 2005, 03:06:05 PM
I am trying to build the structure needed for this.
I don't know how to handle the FILETIME and TCHAR elements.

Can this be modified to find a particular file anywhere on the hard drive or does the path have to be hard coded ?


filexist.asm
EAX = 0  ( file doesn't exist )
   EAX = 1  ( file does exist )

DoesFileExist PROC PUBLIC FileSpec: dword
    LOCAL  findInfo : WIN32_FIND_DATA <>
   
    ; check to see if the file exist on the hard drive by simple using a single API call.
    invoke FindFirstFile, [FileSpec], addr [findInfo]
   
    ; check to return value of FindFirstFile.  If the value is INVALID_HANDLE_VALUE,
    ; the file didn't exist, otherwise it did.
    cmp eax, INVALID_HANDLE_VALUE
    je NotFound

    ; since the file was found, we need to close the handle
    invoke FindClose, eax
    mov eax, 1
    jmp Done

NotFound:
    xor eax, eax

Done:
    ret
DoesFileExist ENDP

WIN32_FIND_DATA STRUCT

    FileAttributes      DWORD     ?
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    FileSizeHigh        DWORD     ?
    FileSizeLow         DWORD     ?
    Reserved0           DWORD     ?
    Reserved1           DWORD     ?
    TCHAR    cFileName[ MAX_PATH ];
    TCHAR    cAlternateFileName[ 14 ];
WIN32_FIND_DATA ENDS
Title: Re: Structure help needed
Post by: pbrennick on February 13, 2005, 04:14:10 PM
Skywalker,
It looks like it is declared correctly.  As far as handling goes, you don't.  It is handled by the FindFirstFile API and then used by the FindNextFile API.  I don't think you should mess with it at all because the FindNextFile API will continue to modify/update it as necessary for use by successive calls until it fails which means you have then found all instances.  You would probably want to echo to standard output the path of all successful finds but that is all, I think.

Paul
Title: Re: Structure help needed
Post by: Grincheux on March 04, 2005, 09:13:56 AM
For testing if a file exists I would prefer to call the "PathFileExists" in the win32 API.

This function return TRUE if the file exist and 0 if it does not exist.

Kenavo