刚学C语言老师让我们把代码注释起来结果发过来没看懂
#ifdef _UNICODE#undef _UNICODE
#endif // _UNICODE
#ifdef UNICODE
#undef UNICODE
#endif // _UNICODE
#include<Windows.h>
#include<stdio.h>
#include<string.h>
#define ONE 1
#define BUFSIZE 1024
int ListDirectoryContents( const char *path );
int main()
{
char path[BUFSIZE] = "D:\\data\\exam\\1";
ListDirectoryContents( path );
//结束
return 0;
}
int ListDirectoryContents( const char *path )
{
WIN32_FIND_DATA fileData = { 0 };
HANDLE h = NULL;
int exit = 0;
char newPath[BUFSIZE] = {0};
char *addressOfLastCharacter = NULL;
//字符串格式化
sprintf( newPath, "%s\\*.*", path );
while(ONE)
{
if( ( h = FindFirstFile( newPath, &fileData ) ) == INVALID_HANDLE_VALUE )
{
printf( "Path not found: [%s]\n", path );
exit = 1;
break;
}
do
{
if( ( strcmp( fileData.cFileName, ".") != 0 ) && ( strcmp( fileData.cFileName, ".." ) != 0 ) )
{
sprintf( newPath, "%s\\%s", path, fileData.cFileName );
if( ( fileData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY) != 0 )
{
ListDirectoryContents( newPath );
}
else
{
printf( "%s\n", fileData.cFileName );
}
}
}
while( FindNextFile( h, &fileData ) );
break;
}
FindClose( h );
return exit;