PDA

View Full Version : [C++] Given a directory, retrieve all files and subdirectories


fseeker
01-23-2007, 12:22 AM
OK, so I need to write this function capable of traversing a directory and retrieving its files (and properties) grouped in subdirectories (if the case).

I will use the stuff retrieved to populate a MySQL table, but the MySQL-part is the simplest ingredient of the task.

I will highly appreciate if you point me to a tutorial or a code snippet. :D

Note:
This has to work on Visual C++ 8.

oracleguy
01-23-2007, 04:33 PM
This kind of thing is platform specific, you are wanting it to work under Windows, Linux/Unix or both?

Mhtml
01-24-2007, 02:09 PM
Well I'd guess Windows if he wishes it to compile in MSVC++... In which case, you'll be wanting to explore CreateFile, FindFirstFileEx, FindNextFile.

Any generic information about the file can be obtained by GetFileInformationByHandle and GetFileAttributesEX. MSDN is your friend here. I'm pretty sure MSVC++ comes with a DVD full of reference material from MSDN doesn't it?

I don't do much for nix, beyond writing reasonably portable code so I can't really help beyond Windows.

oracleguy
01-24-2007, 07:40 PM
Well I'd guess Windows if he wishes it to compile in MSVC++...

Yeah I didn't see that when I read it the first time. Oops.

Those methods that Mhtml mentioned are the ones you want to use. Give them a shot, if you have some specific problems or questions about them, I'm sure we can help you out. They actually aren't that hard to use, they just can be a little confusing at first.