here is the code.
Code: Select all
void ReadDir()
{
fileCount = 0;
DIR *pdir;
struct dirent *pent;
struct stat statbuf;
pdir=opendir(currentDir);
if (pdir)
{
while ((pent=readdir(pdir))!=NULL)
{
stat(pent->d_name,&statbuf);
if(S_ISDIR(statbuf.st_mode))
{
DirList[fileCount] = pent->d_name;
fileCount++;
}
if(!(S_ISDIR(statbuf.st_mode)))
{
DirList[fileCount] = pent->d_name;
fileCount++;
}
}
closedir(pdir);
fileCount--;
}
else
{
iprintf ("opendir() failure; terminating\n");
}
}
Code: Select all
for(i = 0; i <= fileCount; i++)
{
if(i == currentFile)
{
currentFilestr = "*";
}
else
{
currentFilestr = " ";
}
iprintf("%s%s\n", currentFilestr, DirList[i]);
}