BOOL CWebDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
ffFile("","txt")
return TRUE; // return TRUE unless you set the focus to a control
}
這是系統自動的代碼,加了一句ffFile("","txt"),因為添加這個按F9,和F5之后才能進行除錯,才能抓起值,我下面的程式只能讀出檔案夾,第一個冒號填的檔案夾,第二個該填什么呢?
本人剛接觸VC++,請各位能指點一二嗎
在前面的
void CWebDlg::ff(CString strDir,CString strExt)
{
static int i=0,j=0;
CFileFind fileFinder ;
CString strWildcard = strDir;
if(strWildcard.Right(1) != "\\")
strWildcard += "\\";
strWildcard += "*.*";
BOOL fSuccess = fileFinder.FindFile(strWildcard) ;
while (fSuccess)
{
fSuccess = fileFinder.FindNextFile() ;
if (fileFinder.IsDots()) {
continue ;
}
if (fileFinder.IsDirectory())
{
ff(fileFinder.GetFilePath(), strExt) ; //遞回呼叫
}
else
{
CString fpath[1024];
CString fname[1024];
int artnum;
CString strFilePath = fileFinder.GetFileName();
if (0 == strExt.CompareNoCase(PathFindExtension(strFilePath)))
{
fpath[i++]=strFilePath;
fname[j++]=fileFinder.GetFileName();
artnum++;
}
}
}
fileFinder.Close() ;
uj5u.com熱心網友回復:
例子
typedef struct FileInfo
{
string szFileName;
string szFilePath;
string szCreateTime;
}FileInfo;
vector<FileInfo>fileList;
//
void find(LPCTSTR lpPath,vector<FileInfo>& FileList)
{
string szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData);
if(INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/=hFind) return;
//
do
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{// dir
if(FindFileData.cFileName[0] != '.')
{
string szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
//TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList);
}
}
else
{// file
string strFileName=FindFileData.cFileName;//檔案名
//TRACE1("%s\n",strFileName.c_str());
int at = strFileName.find_last_of('.');
if(at<0) continue;// file without extention
string ext=strFileName.substr(at);
//TRACE1("%s\n",ext.c_str());
//
at=0;// reset
while(((int)at=suffixStr.find(ext,at))>=0)// find type
// if(stricmp(suffixStr.c_str(),_T(".txt"))==0)
{// not suffixStr.c_str()==_T(".txt") ; never == !
//afxDump << at << "\n";
at+=ext.size();// move to seperetor '.'
if(suffixStr[at] != '.') continue;// not wanted !
//
FILETIME ft=FindFileData.ftCreationTime;
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft);
FileTimeToSystemTime(&ft,&st);
sprintf(buf,_T("%4d年%02d月%02d日%02d:%02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
string strFilePath=lpPath;
FileInfo fi;
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
//TRACE1("%s\n",strFileName.c_str());
FileList.push_back(fi);
}
}
} while (::FindNextFile (hFind, &FindFileData));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/50074.html
標籤:基礎類
