Link to home
Start Free TrialLog in
Avatar of gshriki
gshriki

asked on

Directory content

I'm looking for a "Directory content" function (like dir in DOS prompt).
ASKER CERTIFIED SOLUTION
Avatar of Paul Maker
Paul Maker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KangaRoo
KangaRoo

If your compiler supports it (virtually all compilers do) take a look at directory streams, in the header <dirent.h>,

#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

int
main (void)
{
  DIR *dp;
  struct dirent *ep;

  dp = opendir ("./");
  if (dp != NULL)
    {
      while (ep = readdir (dp))
        puts (ep->d_name);
      (void) closedir (dp);
    }
  else
    puts ("Couldn't open the directory.");

  return 0;
}
Take a look at the Boost Library at http://www.boost.org

Within the library is a very easy to use, portable and in the running for inclusion within the next C++ standard library.

It includes iterators to directory contents so you can use the std::library without any wrapping whatso ever.

If you have problems using this just ask.

(Theres lots of other good stuff in the library as well)

Regards,

Vic
Hi vickirk, welcome to EE.

All of the experts here, for the most part have learn from other experts as to the proper etiquette for posting answer.

An answer should not be posted as an answer, if other experts have previously posted possible answers as comments, and/or have already made contributions to the question.

There are many experts who never post answers as answer.  Instead, they post their answers as comments.

If you read the following link, you'll see why this is the preferred method for many of our valued experts, including myself.

https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Hi gshriki:
Feel free to click the [Reject Answer] button near (Answer-poster's) response, even if it seems like a good answer.
Doing so will increase your chance of obtaining additional input from other experts.  Later, you can click the [Select Comment as Answer] button on any response.
Avatar of gshriki

ASKER

Sorry vic, couldn't find what I need.
the solution i proposed will only work on a windows platform, but if thats all you want then cool, KangaRoo's solution will work on linux/unix but i can not find that function on VC++
VC++ is one I don't have :-/ Borlands compilers do implement directory as well as MingW32 Cygwin GCC (apart from just Linux/Unix). So, it depends on which compile/OS, again.
to be honest i aint used borland for ages, i use DJGPP gcc sometimes