PathStripToRoot function

Removes all file and directory elements in a path except for the root information.

Note  Misuse of this function can lead to a buffer overrun. We recommend the use of the safer PathCchStripToRoot function in its place.

Syntax


BOOL PathStripToRoot(
  _Inout_  LPTSTR szRoot
);

Parameters

szRoot [in, out]

Type: LPTSTR

A pointer to a null-terminated string of length MAX_PATH that contains the path to be converted. When this function returns successfully, this string contains only the root information taken from that path.

Return value

Type: BOOL

Returns TRUE if a valid drive letter was found in the path, or FALSE otherwise.

Examples



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

void main( void )
{
// Path to convert.
char buffer_1[ ] = "C:\\path1\\path2";
char *lpStr1;
lpStr1 = buffer_1;

// Print the path before the root is stripped.
cout << "The contents of the path before is :      " << lpStr1 << endl;

// Print the return value from the function.
cout << "The return from \"PathStripToRoot\" is :  "
     << PathStripToRoot(lpStr1) << endl;

// Print the path after the root is stripped.
cout << "The contents of the path after is :       " << lpStr1 << endl;
}

OUTPUT:
==================
The contents of the path before is :      C:\path1\path2
The return from "PathStripToRoot" is :  1
The contents of the path after is :       C:\

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

PathStripToRootW (Unicode) and PathStripToRootA (ANSI)

 

 

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.