-2

I have a folder called "test". I need a c++ code that helps me to print all the files from that folder. I don't want to use inotify or ls.

just ME
  • 1,817
  • 6
  • 32
  • 53
  • possible duplicate of [How can I get a list of files in a directory using C or C++?](http://stackoverflow.com/questions/612097/how-can-i-get-a-list-of-files-in-a-directory-using-c-or-c) – INS Feb 02 '12 at 09:11
  • why is this not a real question? – just ME Feb 02 '12 at 10:34
  • it's a duplicate: http://stackoverflow.com/questions/612097/how-can-i-get-a-list-of-files-in-a-directory-using-c-or-c – INS Feb 03 '12 at 07:01

3 Answers3

2

There is a kernel API called inotify that permits to track changes in a directory. A tutorial for inotify is available from IBM here (this could be an alternative to polling the directory for changes, as I understood you want to do...).

Abrixas2
  • 3,207
  • 1
  • 20
  • 22
0
<dir.h>

Next time please do a minimum research by yourself before asking.

m0skit0
  • 25,268
  • 11
  • 79
  • 127
0

The solution I'd recommend is to use boost::filesystem for reading the directory (and manipulating paths), and boost::reg_ex (or std::reg_ex if you have C++11) for checking which filenames match a pattern.

James Kanze
  • 150,581
  • 18
  • 184
  • 329