PathCommonPrefixPathCommonPrefix*
*Contents  *Index  *Topic Contents
*Previous Topic: PathCompactPathEx
*Next Topic: PathFileExists

PathCommonPrefix


int PathCommonPrefix(
    LPCTSTR pszFile1,
    LPCTSTR pszFile2,
    LPTSTR  pszPath
    );

Compares two paths to determine if they share a common prefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".

pszFile1
Address of the first path name.
pszFile2
Address of the second path name.
pszPath
Address of the common prefix in the path.

Example:

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

void main( void )
{
	// String path name 1.
	char buffer_1[] = "C:\\win\\desktop\\temp.txt";
	char *lpStr1;
	lpStr1 = buffer_1;

	// String path name 2.
	char buffer_2[] = "c:\\win\\tray\\sample.txt";
	char *lpStr2;
	lpStr2 = buffer_2;

	// String path out buffer.
	char buffer_3[] = "abcdef";
	char *lpStr3;
	lpStr3 = buffer_3;

	// Variable to get the return. 
	// from "PathCommonPrefix"	
    int	retval;	
    retval = PathCommonPrefix(lpStr1,lpStr2,lpStr3);
    cout << "The contents of String 1:            " << lpStr1 << endl;
    cout << "The contents of String 2:            " << lpStr2 << endl;
    cout << "The length of the output buffer is : "
         << retval << endl;
    cout << "The contents of Output buffer:       " << lpStr3 << endl;
}	
OUTPUT:
-----------
The contents of String 1:            C:\win\desktop\temp.txt
The contents of String 2:            c:\win\tray\sample.txt
The length of the output buffer is : 6
The contents of Output buffer:       C:\win

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