Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

PathIsSameRoot function

Compares two paths to determine if they have a common root component.

Syntax


BOOL PathIsSameRoot(
  _In_  LPCTSTR pszPath1,
  _In_  LPCTSTR pszPath2
);

Parameters

pszPath1 [in]

Type: LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH that contains the first path to be compared.

pszPath2 [in]

Type: LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH that contains the second path to be compared.

Return value

Type: BOOL

Returns TRUE if both strings have the same root component, or FALSE otherwise. If pszPath1 contains only the server and share, this function also returns FALSE.

Examples


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

void main( void )
{
// String path name 1.
char buffer_1[ ] = "C:\\path1\\one";
char *lpStr1;
lpStr1 = buffer_1;

// String path name 2.
char buffer_2[ ] = "C:\\path2\\two";
char *lpStr2;
lpStr2 = buffer_2;

// Variable to get the 
// return from "PathIsSameRoot".
int retval;

// Compare paths with same root.
retval = PathIsSameRoot(lpStr1,lpStr2);

cout << "The return from function is : "
     << retval << endl;
cout << "The contents of String 1:  " << lpStr1
     << "\nThe contents of String 2:  " << lpStr2
     << "\nThese both have the same root part" << endl;

//compare paths with different roots
retval = PathIsSameRoot(lpStr1,"E:\\acme\\three");

cout << "\nThe return from function is : "
     << retval << endl;
cout << "The contents of String 1:  " << lpStr1
     << "\nThe contents of String 3:  E:\\acme\\three"
     << "\nThese do not have the same root part" << endl;
}

OUTPUT:
==================
The return from function is : 1
The contents of String 1:  C:\path1\one
The contents of String 2:  C:\path2\two
These both have the same root part

The return from function is : 0
The contents of String 1:  C:\path1\one
The contents of String 3:  E:\acme\three
These do not have the same root part

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 4.71 or later)

Unicode and ANSI names

PathIsSameRootW (Unicode) and PathIsSameRootA (ANSI)

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.