Main.OpendirInWin History

Hide minor edits - Show changes to output

2006-11-21,01:29 下午 by 61.229.53.62 -
Added lines 1-80:
=cpp [=
#define INC_OLE1 1
#include <windows.h>
#include <stdio.h>

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);
}

void main(int argc, char *argv[])
{
char *pszInputPath;
char pwd[2] = ".";

if (argc < 2)
{
printf("Argument not supplied - using current directory.\n");
pszInputPath = pwd;
}
else
{
pszInputPath = argv[1];
printf("Input Path: %s\n\n", pszInputPath);
}

ScanDir(pszInputPath, 0);

printf("\ndone.\n");
}
=]
 

PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.