WIN32_FIND_DATA FindFileData; if (DirName.GetLength() >= MAX_PATH) printf("File or Directory Name is too " "long: \"%s\"\n", (LPCSTR) DirName); else { // Get first file or directory in the // directory. const HANDLE hFindFile = FindFirstFile(DirName + "\\*.*", &FindFileData); ASSERT(hFindFile != INVALID_HANDLE_VALUE); CString FileName(FindFileData.cFileName); // If there are files and/or directories // in the directory, add all of them to // m_FileList. if (hFindFile != INVALID_HANDLE_VALUE) { do { // Get filename of file or directory. FileName = FindFileData.cFileName; // If the item is a file, add it to // m_FileList. if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { const CString NewLine = DirName + "\\" + FileName; CString NewFileName = NewLine.Right(NewLine.GetLength() - RootDir.GetLength()); NewFileName.MakeUpper(); CObject *pValue = NULL; CFileListItem *pItem = NULL; // If a new item must be created... if (nIndex == 0 || !m_FileList.Lookup(NewFileName, pValue)) { // Create a new item. pItem = new CFileListItem; ASSERT(pItem); pItem->m_bWhichDir[nIndex] = TRUE; // Add new item to m_FileList. m_FileList.SetAt(NewFileName, pItem); } else { ASSERT(pValue && pValue->IsKindOf( RUNTIME_CLASS(CFileListItem))); pItem = (CFileListItem *) pValue; // Update the item which is already // in m_FileList. pItem->m_bWhichDir[nIndex] = TRUE; } } // If item is a directory, add its // files. if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && FileName != "." && FileName != "..") AddFilesToList(RootDir, DirName + "\\" + FileName, nIndex); } while (FindNextFile(hFindFile, &FindFileData)); FindClose(hFindFile); } }
printf("File or Directory Name is too "
"long: \"%s\"\n", (LPCSTR) DirName);
else
{
// Get first file or directory in the
// directory.
const HANDLE hFindFile =
FindFirstFile(DirName + "\\*.*",
&FindFileData);
ASSERT(hFindFile != INVALID_HANDLE_VALUE); CString FileName(FindFileData.cFileName); // If there are files and/or directories
// in the directory, add all of them to
// m_FileList.
if (hFindFile != INVALID_HANDLE_VALUE)
{
do
{
// Get filename of file or directory.
FileName = FindFileData.cFileName; // If the item is a file, add it to
// m_FileList.
if (!(FindFileData.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY))
{
const CString NewLine =
DirName + "\\" + FileName;
CString NewFileName =
NewLine.Right(NewLine.GetLength() -
RootDir.GetLength()); NewFileName.MakeUpper(); CObject *pValue = NULL;
CFileListItem *pItem = NULL; // If a new item must be created...
if (nIndex == 0 ||
!m_FileList.Lookup(NewFileName,
pValue))
{
// Create a new item.
pItem = new CFileListItem;
ASSERT(pItem); pItem->m_bWhichDir[nIndex] = TRUE; // Add new item to m_FileList.
m_FileList.SetAt(NewFileName, pItem);
}
else
{
ASSERT(pValue && pValue->IsKindOf(
RUNTIME_CLASS(CFileListItem))); pItem = (CFileListItem *) pValue; // Update the item which is already
// in m_FileList.
pItem->m_bWhichDir[nIndex] = TRUE;
}
} // If item is a directory, add its
// files.
if (FindFileData.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY &&
FileName != "." && FileName != "..")
AddFilesToList(RootDir, DirName +
"\\" + FileName,
nIndex);
} while (FindNextFile(hFindFile,
&FindFileData)); FindClose(hFindFile);
}
}
文件自动填充,你自己找找看