[main] [more portable]

On codesnippets

List the contents of a directory in C/C++

Unfortunatly neither the C nor the C++ standard define a way to clear the screen in their standard library. This means you will have to resort a platform specific library.

I've written a header file which abstracts this functionality in a simple to use class oslink::directory. I wrote this header to work at least for Win32 console applications and for Linux. It will probably work other platforms support POSIX too, but that's untested.

This is a work in progress. Mail me with suggestions or improvements to bvh-cplusplus@irule.be.

osdir.h

Win32 console application - Microsoft Visual C++

Download the osdir.h header and add copy it to your project directory. Next select the fileview tab in the workspace pane and right click on Header files. Select Add files to folder from the context menu and select osdir.h.

Using osdir.h

#include "osdir.h"
#include 

int main()
{
   oslink::directory dir("directory_name");
   while (dir)
      std::cout << dir.next() << std::endl;
}

The call to dir.next() returns a std::string with the next entry in the directory directory_name.

More examples on using osdir (both under windows and linux). A complete example on walking an entire filesystem is included.