Platform SDK: Files and I/O

SearchPath

The SearchPath function searches for the specified file.

DWORD SearchPath(
  LPCTSTR lpPath,      // search path
  LPCTSTR lpFileName,  // file name
  LPCTSTR lpExtension, // file extension
  DWORD nBufferLength, // size of buffer
  LPTSTR lpBuffer,     // found file name buffer
  LPTSTR *lpFilePart   // file component
);

Parameters

lpPath
[in] 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/2000: 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/2000: The 16-bit Windows system directory. There is no Win32 function that retrieves 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
[in] Pointer to a null-terminated string that specifies the name of the file to search for.
lpExtension
[in] Pointer to a null-terminated string that specifies an extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension.

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

nBufferLength
[in] Specifies the length, in TCHARs, of the buffer that receives the valid path and file name.
lpBuffer
[out] Pointer to the buffer that receives the path and file name of the file found.
lpFilePart
[out] Pointer to the variable that receives the address (within lpBuffer) of the last component of the valid path and file name, 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 TCHARs, 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.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

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