SearchPath

The SearchPath function searches for the specified file.

DWORD SearchPath(
  LPCTSTR lpPath,      // pointer to search path
  LPCTSTR lpFileName,  // pointer to filename
  LPCTSTR lpExtension, // pointer to extension
  DWORD nBufferLength, // size, in characters, of buffer
  LPTSTR lpBuffer,     // pointer to buffer for found filename
  LPTSTR *lpFilePart   // pointer to pointer to file component
);
 

Parameters

lpPath
Pointer 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
Pointer to a null-terminated string that specifies the name of the file to search for.
lpExtension
Pointer 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
Pointer to the buffer for the valid path and filename of the file found.
lpFilePart
Pointer 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.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also

File I/O Overview, File Functions, FindFirstFile, FindNextFile, GetSystemDirectory, GetWindowsDirectory