Contents Index Topic Contents | ||
Previous Topic: PathAddBackslash Next Topic: PathAppend |
PathAddExtension
BOOL PathAddExtension( LPTSTR pszPath, LPCTSTR pszExtension );Adds a file extension to a string.
- Returns TRUE if successful, or FALSE otherwise.
- pszPath
- Address of the string to which the file extension will be added.
- pszExtension
- Address of the string that contains the file extension.
If there is already a file extension present, no extension will be added. If the path is a null string, the result will be the file extension only.
Example:
#include <windows.h> #include <iostream.h> #include "Shlwapi.h" void main( void ) { // String for path name without file extension. char buffer_1[] = "file"; char *lpStr1; lpStr1 = buffer_1; // String for path name with file extension. char buffer_2[] = "file.doc"; char *lpStr2; lpStr2 = buffer_2; // String for extension name. char F_Ext[] = ".txt"; char *lpStr3; lpStr3 = F_Ext; // Null string as path. char N_String[] = "\0"; char *lpStr4; lpStr4 = N_String; // Path 1 without the file extension. cout << "The original path string 1 is " << lpStr1 << endl; int ret_1 = PathAddExtension(lpStr1,lpStr3); cout << "The modified path string 1 is " << lpStr1 << endl; // Path 2 with the file extension already there. cout << "The original path string 2 is " << lpStr2 << endl; int ret_2 = PathAddExtension(lpStr2,lpStr3); cout << "The modified path string 2 is " << lpStr2<< endl; // Path 3 null string as a path. int ret_3 = PathAddExtension(lpStr4,lpStr3); cout << "The return value is " << ret_3<< endl; cout << "The modified path on a null string is " << lpStr4<< endl; int ret_4 = PathAddExtension("sample",""); cout << "The return value is " << ret_4<< endl; if(ret_4 != 1) {cout << "The PathAddExtension failed" << endl;} else {cout << "The PathAddExtension succeeded" << endl;} } OUTPUT: ----------------------- The original path string 1 is file The modified path string 1 is file.txt The original path string 2 is file.doc The modified path string 2 is file.doc The return value is 1 The modified path on a null string is .txt The return value is 1 The PathAddExtension succeeded
Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.