msdn原文送上#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.txtThe path without file spec is : C:\TEST
CString strExt(".PDF");
CString strFile2;
strFile2=strFile.Left(strFile.ReverseFind('.'))+strExt;
例如:
file=“c:\\file\\file1.txt";
如何取得“c:\\file\\”
#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.txtThe path without file spec is : C:\TEST
例如:
file=“c:\\file\\file1.txt ";
如何取得“c:\\file\\”
----------------------------CString file = "c:\\file\\file.txt";
file = file.Left(file.ReverseFind('\\'));