📄 myfileapp.cpp
字号:
#include "stdafx.h"
#include "MyFileApp.h"
#include "stdlib.h"
#include "io.h" // 包含 _findfirst(), _findnext()函数原型
#include "direct.h" // 包含 _chdir()函数原型
#include "errno.h" // 包含系统变量errno
CString ChangeFileName(CString sourceName, CString newAffix)
{// 在原文件名后加任意字符产生新文件名,文件后缀名为txt
int i=sourceName.ReverseFind('.'); // 从后向前搜索圆点
int j=sourceName.ReverseFind('\\'); // 从后向前搜索反斜杠
if (i>j) return sourceName.Left(i)+newAffix+".txt";
else return sourceName+newAffix+".txt";
}
CString ChangeExt(CString oldName,CString newExt)
{// 将原文件名的后缀部分改为新的后缀名
int i=oldName.ReverseFind('.');
int j=oldName.ReverseFind('\\');
if(i>j)
return oldName.Left(i+1)+newExt;
else
return oldName+"."+newExt;
}
int ProcessFiles(char *Ext, char * Name, void(* ProcessAFile)(CString fileName))
{
CFileDialog dlg(TRUE, Ext, Name, OFN_ALLOWMULTISELECT);
CString strFileNames; // 分配一片空间存放文件名,可以选取多个文件
dlg.m_ofn.lpstrFile = strFileNames.GetBuffer(2048);
dlg.m_ofn.nMaxFile = 2048;
if(dlg.DoModal()!=IDOK) {
AfxMessageBox("您没有选取任何文件!");
return 0;
}
strFileNames.ReleaseBuffer();
int fileCount = 0;
CString FileName;
POSITION pos = dlg.GetStartPosition(); // 获取第一个文件名的起点位置
while(pos!=NULL) { // 如果有文件可以获取
FileName = dlg.GetNextPathName(pos); // 获取文件名,并移到下一个文件名的起始位置
ProcessAFile(FileName); // 调用处理单个文件的函数
fileCount ++; // 这里有点问题,实际上并不知道是否"真的"处理了文件,
// 也许调用的函数打开了一个文件但不符合处理要求,
// 根本没有处理文件
}
AfxMessageBox("全部文件处理完毕!");
return fileCount; // 返回文件个数
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -