Prev Next

SearchPath info  Overview  Group

The SearchPath function searches for the specified file.

DWORD SearchPath(

    LPCTSTR lpPath,

// address of search path

    LPCTSTR lpFileName,

// address of filename

    LPCTSTR lpExtension,

// address of extension

    DWORD nBufferLength,

// size, in characters, of buffer

    LPTSTR lpBuffer,

// address of buffer for found filename

    LPTSTR *lpFilePart 

// address of pointer to file component

   );

Parameters

lpPath
Points to a null-terminated string that specifies the path to be searched for the file. If this parameter is NULL, the function searches for a matching file in the following directories in the following sequence:
  1. The directory from which the application loaded.

  2. The current directory.

  3. Windows 95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

    Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32.

  4. Windows NT: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM.

  5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.

  6. The directories that are listed in the PATH environment variable.
lpFileName
Points to a null-terminated string that specifies the name of the file to search for.
lpExtension
Points to a null-terminated string that specifies an extension to be added to the filename when searching for the file. The first character of the filename extension must be a period (.). The extension is added only if the specified filename does not end with an extension.

If a filename extension is not required or if the filename contains an extension, this parameter can be NULL.

nBufferLength
Specifies the length, in characters, of the buffer that receives the valid path and filename.
lpBuffer
Points to the buffer for the valid path and filename of the file found.
lpFilePart
Points to the address (within lpBuffer) of the last component of the valid path and filename, which is the address of the character immediately following the final backslash (\) in the path.

Return Values

If the function succeeds, the value returned is the length, in characters, of the string copied to the buffer, not including the terminating null character. If the return value is greater than nBufferLength, the value returned is the size of the buffer required to hold the path.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

See Also

FindFirstFile, FindNextFile, GetSystemDirectory, GetWindowsDirectory

See: