PathRemoveFileSpec
http://technet.microsoft.com/zh-cn/magazine/bb773748(en-us,VS.85).aspx
PathRemoveFileSpec function
Removes the trailing file name and backslash from a path, if they are present.
Syntax
BOOL PathRemoveFileSpec( __inout LPTSTR pszPath );
Parameters
- pszPath [in, out]
-
Type: LPTSTR
A pointer to a null-terminated string of length MAX_PATH that contains the path from which to remove the file name.
Return value
Type: BOOL
Returns nonzero if something was removed, or zero otherwise.
Examples
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
void main( void )
{
// Path to include file spec.
char buffer_1[ ] = "C:\\TEST\\sample.txt";
char *lpStr1;
lpStr1 = buffer_1;
// Print the path with the file spec.
cout << "The path with file spec is : " << lpStr1 << endl;
// Call to "PathRemoveFileSpec".
PathRemoveFileSpec(lpStr1);
// Print the path without the file spec.
cout << "\nThe path without file spec is : " << lpStr1 << endl;
}
OUTPUT:
==================
The path with file spec is : C:\TEST\sample.txt
The path without file spec is : C:\TEST
Requirements
Minimum supported client |
Windows 2000 Professional, Windows XP |
---|---|
Minimum supported server |
Windows 2000 Server |
Header |
|
Library |
|
DLL |
|
Unicode and ANSI names |
PathRemoveFileSpecW (Unicode) and PathRemoveFileSpecA (ANSI) |