1. 如何获得运行程序当前所在文件夹地址
char szFolder[1024] = {0};
::GetModuleFileName(NULL,szFolder,1024);
CString Temp = _T(szFolder);
int pos = Temp.ReverseFind('\\');
CString StrFolderTemp(szFolder,pos);
StrFolder.Format("%s",StrFolderTemp);
CString StrName="test";
hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,StrName);
if(hMutex==NULL){
hMutex=::CreateMutex(NULL,NULL,StrName);
}else{
if(AfxMessageBox("程序实例已经存在",MB_ICONQUESTION|MB_YESNO==IDYES)){
return FALSE;
}
}
void MyFolder::RecursiveDelete(CString Path){
CFileFind ff;
CString cPath=Path;
if(cPath.Right(1)!="\\"){
cPath+="\\";
}
cPath+="*";
BOOL res=ff.FindFile(cPath);
while(res){
res=ff.FindNextFile();
CString name=ff.GetFilePath();
if(!ff.IsDots()&&!ff.IsDirectory()){
DeleteFile(ff.GetFilePath());
}else if(ff.IsDots()){
continue;
}else if(ff.IsDirectory()){
cPath=ff.GetFilePath();
RecursiveDelete(cPath);
RemoveDirectory(cPath);
}
}
}
char *From = "F:\\test.txt\0";
char *To = "E:\\test.txt\0";
SHFILEOPSTRUCT op;
ZeroMemory(&op, sizeof(op));
op.hwnd = NULL; // 主窗体或应用程序的句柄,允许为NULL
op.wFunc = FO_COPY; //此处可改变,执行移动功能(FO_MOVE)
op.pFrom = From;
op.pTo = To;
op.fFlags= 0;
SHFileOperation( &op);