给你一个思路先遍历这个文件夹下的txt文件,然后逐个创建比较时间,并保存最新的文件名到一个变量上面,然后用CFile::read 读取内容。
给你一段伪代码 自己修改试试
HANDLE hSearchWIN32_FIND_DATA FileData, tempFileData
hSearch = FindFirstFile("E:\\XX\\*.txt", &FileData) //首先找到的是“.”
if (hSearch == INVALID_HANDLE_VALUE)return 0
if (! FindNextFile(hSearch, &FileData)) return 0 //然后找到的是“..”
FindNextFile(hSearch, &tempFileData)//把第一个文件的信息保存在tempFileData上
while (1)
{
if (!FindNextFile(hSearch, &FileData))
break
else
{
if(CompareFileTime(FileData.ftCreationTime ,tempFileData.ftCreationTime )==-1){
tempFileDataFileData
}
}
}
FindClose(hSearch)
CFile file
file.open("路径+\\tempFileData.cFileName")
char buf[xx]
file.read(buf......)
file.close()
这个嘛,我原来也做过这个问题的,当时是在MSDN找到示例后,自己做过的改动的,主要是用CFileFind这个类,然后递归调用,具体的你看看下面的代码!希望对你有用。。。不懂的可以交流嘛void CMusicFileManagerDlg::SearchDirectory(CString strFolderPath, UINT&nCount)
{
CFileFind finder
UpdateData(TRUE)
FileAtt* att = new FileAtt
CString str = strFolderPath
if(str != "" &&str.Right(1) != '\\')//为全目录名添加'\'
str += '\\'
strFolderPath = str
BOOL bWorking = finder.FindFile(strFolderPath + _T("*.*"))
LVITEM item
item.mask = LVIF_TEXT
item.iSubItem = 0
while(bWorking)
{
bWorking = finder.FindNextFile()
if(finder.IsDirectory() &&!finder.IsDots())
{
strFolderPath = finder.GetFilePath()
//AfxMessageBox(strFolderPath)
SetDlgItemText(IDC_STATIC_CURSEARCHDIR, strFolderPath)
SearchDirectory(strFolderPath, nCount)
}
else if( (strFolderPath = finder.GetFilePath()).Right(4).MakeLower() == _T(".mp3")
//|| (strFolderPath = finder.GetFilePath()).Right(4).MakeLower() == _T(".wma")
)
{
if(GetFileAttrib(strFolderPath, att) == false)
AfxMessageBox(_T("文件[") + strFolderPath + _T("]未读取成功"),MB_ICONQUESTION)
CString temp(att->ID3V1)
TRACE(temp + _T(" "))
if(strcmp(att->ID3V1, "TAG"))
continue
item.iItem = ++nCount
CString temp1(att->title)
TRACE(_T("title = %d\n"), strlen(att->title))
if(strlen(att->title) >0)
{
item.pszText =(LPTSTR)(LPCTSTR)(temp1)
m_filelist.InsertItem(&item)
}
else //如果是空的标题,则自动替换为文件名
{
CString str = finder.GetFileTitle()
item.pszText = (LPTSTR)(LPCTSTR)(str)
m_filelist.InsertItem(&item)
}
CString temp2
strlen(att->singer) >0 ? temp2 = att->singer : temp2 = _T("未知艺术家")
m_filelist.SetItemText(nCount - 1, 1, temp2)
CString temp3
strlen(att->album) >0 ? temp3 = att->album : temp3 = _T("未知专辑")
m_filelist.SetItemText(nCount - 1, 2, temp3)
int q = int(att->type[0])
if(q >-1 &&q <116)
{
CString temp4(convert[int(att->type[0])])
m_filelist.SetItemText(nCount - 1, 3, temp4)
}
else
{
CString temp4("Unknown")
m_filelist.SetItemText(nCount - 1, 3, temp4)
}
CString temp5(att->year)
m_filelist.SetItemText(nCount - 1, 4, temp5)
m_filelist.SetItemText(nCount - 1, 5, finder.GetRoot())
m_filelist.SetItemText(nCount - 1, 6, finder.GetFileName())
CString strfilename = finder.GetFileName()
CString strfiletitle = finder.GetFileTitle()
int nextLength = strfilename.GetLength() - strfiletitle.GetLength()
strfilename = strfilename.Right(nextLength - 1)
m_filelist.SetItemText(nCount - 1, 7, strfilename)
}
}//end of while
finder.Close()
m_nCount = nCount
UpdateData(FALSE)
delete att
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)