要删除的文件肯定是存在的,编译,链接都通过了,但是执行的时候就会出异常,不知道是为什么?

我自己写的测试源码如下:
#include "iostream"
#include "afx.h"
#include "string"
using namespace std;
int main(){
CFileFind finder;
CString path("d:\\");
BOOL hasNext;
hasNext = finder.FindFile(path+"\\1.*");
while(hasNext){
hasNext = finder.FindNextFile();
cout<<(LPCTSTR)finder.GetFilePath()<<endl;
char* pFile = (LPSTR)(LPCTSTR)finder.GetFilePath();
TCHAR* pFileName = _T(pFile);
CFile::Remove(pFileName);
}
return 1;
}






Helenr
浏览 63回答 2
2回答

胡说叔叔

如果文件被打开,或被使用中,或是只读文件(保护状态下 attrib 显示 R 的文件),不让删的。CString path("d:\\");hasNext = finder.FindFile(path+\\1.*); -- 相连后,4个反斜杠 是不是多了。

拉丁的传说

我不是学C的,也没弄过这种,不过char* pFile = (LPSTR)(LPCTSTR)finder.GetFilePath();//应该只是获取路径吧,好像不包括文件名的,也就是d:\
打开App,查看更多内容
随时随地看视频慕课网APP