对话框读取文件路径
CFileDialog dialog(TRUE, "data", "*.txt", OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T(".data(*.txt)|*.txt||"), NULL);
if (dialog.DoModal() != IDOK)
return;
string path_data = dialog.GetPathName();
读取当前路径下所有文件
CFileDialog dialog(TRUE, "image", "*.png", OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T(".data(*.png)|*.png||"), NULL);
if (dialog.DoModal() != IDOK)
return;
string path_in = dialog.GetPathName();
int pos = path_in.find_last_of('\\');
string path_file = path_in.substr(0, pos);
vector<string> path_image; //完整的图片路径
vector<string> name_image; //图片的名字
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path_file).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{ /*
if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
getFiles( p.assign(path).append("\\").append(fileinfo.name), files, ownname ); */
}
else
{
path_image.push_back(p.assign(path_file).append("\\").append(fileinfo.name));
name_image.push_back(fileinfo.name);
}
}while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
判断文件路径是否存在,若不存在,则创建
CString strFolderPath;
strFolderPath = _T("D:\\无线通信板报文存储文件夹");
if(!PathIsDirectory(strFolderPath))//判断路径是否存在
CreateDirectory(strFolderPath,NULL);//新建文件夹