WIN32_FIND_DATA FindMusicName;
HANDLE FindHand;
CString FindNameStr("");
int listItem = 0; //这个是用在list控件显示文件用的
ZeroMemory(&FindMusicName,sizeof(WIN32_FIND_DATA)); //清空结构体内存控件
CString FindPath = FolderPath + "\\*"; //只有当后面有\*时才能浏览文件夹
//folderPath //是文件夹的路径
FindHand = FindFirstFile(FindPath,&FindMusicName); //获取第一个文件的句柄
if (FindHand == INVALID_HANDLE_VALUE)
{
MessageBox(_T("查看文件失败"));
return;
}
while(1)
{
if (FindNextFile(FindHand,&FindMusicName))
{
FindNameStr = FindMusicName.cFileName;
if (FindNameStr.Right(FindNameStr.GetLength()- FindNameStr.ReverseFind('.')-1) == "mp3")
{
m_MusicListCtr.InsertItem(listItem,FindNameStr); //插入list控件中
}
listItem++;
}
else
break;
}
FindClose(FindHand);