0

In C++, how can we find programatically while looping thourhg a directory structure if it is subdirectory or is it a file. This i want to perform with functions avaialble in C++ standard, with out using Boost or system call and implementaiton should be portable.

venkysmarty
  • 11,099
  • 25
  • 101
  • 184

2 Answers2

2

Without a portable library (boost comes to mind) you will not be able to do this portably (pun may be intended). The c++ standard does not have this type of functionality.

Why do you not want to use boost?

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
0

The readdir() function from the standard C library should do the trick. See http://linux.die.net/man/3/readdir for some basic documentation of it.

The dirent struct should contain the necessary information to tell the type of each file.

Catfish_Man
  • 41,261
  • 11
  • 67
  • 84
  • 1
    I believe that `readdir()` is not standard C but rather POSIX. At any rate I don't think it can be used in windows with Visual Studio directly. – David Rodríguez - dribeas Jan 20 '11 at 10:05
  • Hm, 'man readdir' on my OSX machine says "Standard C Library", but perhaps it's referring to "libc the binary on disk" rather than "the C library spec". I'm unfamiliar with the Windows APIs, so I won't be much help beyond that. – Catfish_Man Jan 20 '11 at 10:08
  • I am not sure about it, I don't code in windows either, but looking at the C99 draft I did not find it, and google search for "readdir windows" shows that some people have tried and are [looking for alternatives](http://stackoverflow.com/questions/883594/microsoft-visual-studio-opendir-and-readdir-how). – David Rodríguez - dribeas Jan 20 '11 at 10:21