tags:

views:

123

answers:

3

I come from a C# background and I am working on a C++ project. I need to open files in a directory, then process that data in the files. The problem is on my target environment (Greenhills Integrity), I cannot access a "directory". It seems C++ does not have a concept of a directory. Why not? This problem is simple in C#. I cannot link to any big library(BOOST or dirent) to get the files. I can open a file using fopen, but I won't always know the file names, so I have to "strcat" the directory to each filename in order to "fopen" the files.

I need a way to just get the file names in a directory without using an external API. Is that possible?

+4  A: 

The major C++ APIs have directories. Start with readdir on POSIX or FindFirstFile() on Windows. Greenhills seems to support POSIX.

Matthew Flaschen
Why the downvote?
Matthew Flaschen
@Matthew: Maybe someone thought that hints for accomplishing something on Win32 and Unix aren't all that helpful for someone hacking on Greenhills Integrity? Mind you, while it wasn't me, I wouldn't blame them.
sbi
I initially down-voted because readdir is not a generic C++ function; however have re-upvoted since the edit to indicate the required function is operating specific.
PP
+3  A: 

No, it's not possible. C++ has no "built-in" directory functionality - you need to use a library of some sort.

anon
Of course it's possible. While C++ doesn't have any specific directory classes (like the file streams) you can just the underlying system calls - readdir et al. http://www.cs.cf.ac.uk/Dave/C/node20.html
Andy Shellam
readdir isn't a system call. All I/O in C++ (as in C) is prerformed via libraries.
anon
+2  A: 

Check with your operating system. Directory handling is different for each. You will have to use the Windows 32 API if you want to list/query directories on Microsoft Windows, and the Linux API (e.g. opendir/stat) if you want to list/query directories on Linux.

PP
See http://stackoverflow.com/questions/883594/microsoft-visual-studio-opendir-and-readdir-how
PP