?? 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 + -