Я проверял для Windows - отлично работает :)
Below is a directory lister for Windows, Unix/POSIX and MS-DOS.
#include
#ifdef _WIN32
/* Compiling for Windows */
#include
int main(void)
{
WIN32_FIND_DATA f;
HANDLE h = FindFirstFile("./*", &f);
if(h != INVALID_HANDLE_VALUE)
{
do
{
puts(f.cFileName);
} while(FindNextFile(h, &f));
}
else
{
fprintf(stderr, "Error opening directory\n");
}
return 0;
}
#else
#ifdef __unix__
/* Compiling for UNIX / POSIX */
#include
#include
int main(void)
{
DIR *dir = opendir(".");
if(dir)
{
struct dirent *ent;
while((ent = readdir(dir)) != NULL)
{
puts(ent->d_name);
}
}
else
{
fprintf(stderr, "Error opening directory\n");
}
return 0;
}
#else
#ifdef __TURBOC__
/* Compiling for MS-DOS */
#include
int main(void)
{
struct ffblk ffblk;
if(findfirst("*.*", &ffblk, 0) == 0)
{
do
{
puts(ffblk.ff_name);
} while(findnext(&ffblk) == 0);
}
else
{
fprintf(stderr, "Error opening directory\n");
}
return 0;
}
#else
#error Unsupported Implementation
#endif
#endif
#endif
Комментариев нет:
Отправить комментарий