在Windows下对文件目录结构的操作问题如:c://vc++//hello.cpp..
在Windows下对文件目录结构的操作问题如:c://vc++//hello.cpp..
我怎么找到 文件hello
问题点数:100、回复次数:4Top
1 楼juan666(菜鸟)回复于 2005-06-23 11:07:53 得分 90
不懂啊 帮顶,好象没有要写一个函数很麻烦啊Top
2 楼EmbraceTM()回复于 2005-06-23 11:33:38 得分 10
void ScanDir(char *dirname, int indent)
{
BOOL fFinished;
HANDLE hList;
TCHAR szDir[MAX_PATH+1];
TCHAR szSubDir[MAX_PATH+1];
WIN32_FIND_DATA FileData;
// Get the proper directory path
sprintf(szDir, "%s\\*", dirname);
// Get the first file
hList = FindFirstFile(szDir, &FileData);
if (hList == INVALID_HANDLE_VALUE)
{
printf("No files found\n\n");
}
else
{
// Traverse through the directory structure
fFinished = FALSE;
while (!fFinished)
{
// Check the object is a directory or not
if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((strcmp(FileData.cFileName, ".") != 0) &&
(strcmp(FileData.cFileName, "..") != 0))
{
printf("%*s%s\\\n", indent, "",
FileData.cFileName);
// Get the full path for sub directory
sprintf(szSubDir, "%s\\%s", dirname,
FileData.cFileName);
ScanDir(szSubDir, indent + 4);
}
}
else
printf("%*s%s\n", indent, "", FileData.cFileName);
if (!FindNextFile(hList, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
fFinished = TRUE;
}
}
}
}
FindClose(hList);
}
Top
3 楼EmbraceTM()回复于 2005-06-23 11:35:19 得分 0
其时就是文件的遍历!
用 FindFirstFile(), FindNextFile(),
没什么难的!Top
4 楼EmbraceTM()回复于 2005-06-24 08:35:38 得分 0
我靠!
明摆了是马夹.............Top




