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

PathIsPrefix function

Searches a path to determine if it contains a valid prefix of the type passed by pszPrefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".

Syntax


BOOL PathIsPrefix(
  _In_  IN LPCTSTR pszPrefix,
  _In_  IN LPCTSTR pszPath
);

Parameters

pszPrefix [in]

Type: IN LPCTSTR

A pointer to a null-terminated string of maximum length MAX_PATH that contains the prefix for which to search.

pszPath [in]

Type: IN LPCTSTR

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

Return value

Type: BOOL

Returns TRUE if the compared path is the full prefix for the path, or FALSE otherwise.

Examples


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

void main( void )
{
// Path prefix 1.
char buffer_1[ ] = "C:\\";
char *lpStr1;
lpStr1 = buffer_1;

// Path prefix 2.
char buffer_2[ ] = "C:\\test\\Some\\sample";
char *lpStr2;
lpStr2 = buffer_2;

// Path prefix 3.
char buffer_3[ ] = "sample"; 
char *lpStr3;
lpStr3 = buffer_3;

// Search a path prefix with result true.
cout << "The contents of path 1 is : " << lpStr1
     << "\nThe contents of path 2 is : " << lpStr2
     << "\nThe return from the function is : "
     <<  PathIsPrefix(lpStr1,lpStr2)
     << "\nPathIsPrefix returns TRUE   "
     << "\nand Path lpStr1 and lpStr2"
     << "\nhave the same prefix :" << endl;

// Search a path prefix with result false.
cout << "\nThe contents of path 1 is : " << lpStr1
     << "\nThe contents of path 3 is : " << lpStr3
     << "\nThe return from the function is : "
     <<  PathIsPrefix(lpStr1,lpStr3)
     << "\nPathIsPrefix returns FALSE   "
     << "\nand Path lpStr1 and lpStr3"
     << "\nhave different prefixes :" << endl;
}

OUTPUT:
==============
The contents of path 1 is : C:\
The contents of path 2 is : C:\test\Some\sample
The return from the function is : 1
PathIsPrefix returns TRUE
and Path lpStr1 and lpStr2
have the same prefix :

The contents of path 1 is : C:\
The contents of path 3 is : sample
The return from the function is : 0
PathIsPrefix returns FALSE
and Path lpStr1 and lpStr3
have different prefixes :
			

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

PathIsPrefixW (Unicode) and PathIsPrefixA (ANSI)

 

 

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

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.