PathCombinePathCombine*
*Contents  *Index  *Topic Contents
*Previous Topic: PathCanonicalize
*Next Topic: PathCompactPath

PathCombine


PathCombine(
    LPTSTR  lpszDest,
    LPCTSTR lpszDir,
    LPCTSTR lpszFile
    );

Concatenates two strings that represent properly formed paths into one path, as well as any relative path pieces.

lpszDest
Address of the combined path.
lpszDir
Address of the string that represents the directory path.
lpszFile
Address of the string that represents the file path.

The directory path should be in the form of A:,B:, ..., Z:. The file path should be in a correct form that represents the file part of the path. The file path must not be null, and if it ends with a backslash, the backslash will be maintained.

Example:

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
	// Buffer to hold combined path.
	char buffer_1[] = "";
	char *lpStr1;
	lpStr1 = buffer_1;

	// String for balance of path name.
	char buffer_2[] = "One\\Two\\Three";
	char *lpStr2;
	lpStr2 = buffer_2;

	// String for directory name.
	char buffer_3[] = "C:";
	char *lpStr3;
	lpStr3 = buffer_3;

cout << "The file path to be combined is  " 
     << lpStr2<< endl;
cout << "The directory name path is       " 
     << lpStr3<< endl;
cout << "The combined path is             " 
     << PathCombine(lpStr1,lpStr3,lpStr2) << endl;

}
------------
INPUT:
------------
Path for directory part: "C:"
Path for file part: "One\Two\Three"
------------
OUTPUT:
------------
The file path to be combined is  One\Two\Three
The directory name path is       C:
The combined path is             C:\One\Two\Three

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.