Sign in to follow this  

Get a list of file names in present dir?

This topic is 4336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, that's pretty much my question. I am compiling C++ in Visual Studio 7. I'm working on saving the game state right now, but I'd like to know how to determine what save files already exist in a particular directory. Does anyone know of any system calls I can make to list out all of the filename strings in a given directory? Thanks much, jujumbura

Share this post


Link to post
Share on other sites
Well,

I didn't find anything called "FindFileFirst" or "FindFileNext". What I did find is a class called "CFileFind", which seems to do what I'd like, according to the documentation.

Unfortunately, I'm getting linker errors when I try to use it. The documentation says that it needs me to include "afx.h", but the example they provide shows an include of "afxwin.h". If I include either one of these, I get a compiler error saying that the new and new[] operators are being defined twice.

Any ideas?

Share this post


Link to post
Share on other sites
Quote:
Original post by jujumbura
Well,

I didn't find anything called "FindFileFirst" or "FindFileNext". What I did find is a class called "CFileFind", which seems to do what I'd like, according to the documentation.

Unfortunately, I'm getting linker errors when I try to use it. The documentation says that it needs me to include "afx.h", but the example they provide shows an include of "afxwin.h". If I include either one of these, I get a compiler error saying that the new and new[] operators are being defined twice.

Any ideas?

CFileFind is an MFC class. What you want is FindFirstFile and FindNextFile.

Sorry for the misnaming, but I don't see why anyone would rate me down for that. This is a very strange place.

Share this post


Link to post
Share on other sites
Thanks all,

After seeing the proper spelling, I did indeed get FindFirstFile and FindNextFile to give me the results I needed.

And Mercury, I wouldn't dream of it; I'm happy for any help I get, misspelled or not.

jujumbura

Share this post


Link to post
Share on other sites
Quote:
Original post by bengaltgrs
Is there a better way to find all the existing files in a directory in C#, or would using the same C# equivelent functions be the best way?

-Chris


The best way to list files in a directory in C# is with DirectoryInfo

Eg:

#using System.IO;

DirectoryInfo di = new DirectoryInfo( "." );
FileInfo[] files = di.GetFiles( "*.*" );

//Optional
foreach( FileInfo fi in files )
{
// Do something with files
Console.WriteLine( fi.Name );
}

Share this post


Link to post
Share on other sites

This topic is 4336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this