·Âwindows dir.exe
#include <windows.h>#include <stdio.h>
DWORD ListDir(LPSTR szPath)
{
WIN32_FIND_DATA ListFile;
HANDLE hListFile;
CHAR szFilePath;
SYSTEMTIME stFileTime;
lstrcpy(szFilePath, szPath);
lstrcat(szFilePath, "\\*");
hListFile = FindFirstFile(szFilePath, &ListFile);
if (hListFile != INVALID_HANDLE_VALUE)
{
do
{
FileTimeToSystemTime(&ListFile.ftCreationTime, &stFileTime);
printf("%d-%02d-%02d %02d:%02d\t", stFileTime.wYear, stFileTime.wMonth, stFileTime.wDay, stFileTime.wHour, stFileTime.wMinute);
if (ListFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
printf("<DIR>\t");
}
else
{
printf("\t%ld", ListFile.nFileSizeHigh * (MAXDWORD + 1) + ListFile.nFileSizeLow);
}
printf("\t%s\n", ListFile.cFileName);
}while (FindNextFile(hListFile, &ListFile));
}
return 0;
}
int main(int argc, PCHAR argv[])
{
if (argc == 2)
{
ListDir(argv);
}
else
{
CHAR szCurPath;
GetCurrentDirectory(MAX_PATH, szCurPath);
ListDir(szCurPath);
}
return 0;
}
Ò³:
[1]