Jump to content
  • Advertisement
Sign in to follow this  
Malchivus

how to list files in a folder?

This topic is 4809 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

Heya, I know this is something that you see on the internet, but I can't seem to get anything to do it... I am using mingw32, is there a (GCC) way (i.e. a set of functions in one of the libs) that will let me find out all of the files in a directory? I know there are things for windows, and for *nix, but I want to do it in a way that works everywhere ... or is this one of those places where you need to write a separate path for each platform ...

Share this post


Link to post
Share on other sites
Advertisement
There is a windows specific way if you want.
it looks like this:


WIN32_FIND_DATA FindFileData;
HANDLE hFind;

printf ("Target file is %s.\n", argv[1]);
hFind = FindFirstFile("*\0", &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError ());
return (0);
}

do
{
printf ("The first file found is %s\n", FindFileData.cFileName);


if( FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{
if( strcmp( FindFileData.cFileName, ".\0" ) && strcmp( FindFileData.cFileName, "..\0" ) )
{
printf( "\n" );

//should recurse here
WIN32_FIND_DATA FindFileData1;
HANDLE hFind1;

string st;

st.append( FindFileData.cFileName );
st.append( "\\*" );
printf( "string=%s\n", st.c_str() );


hFind1 = FindFirstFile( st.c_str(), &FindFileData1 );

cout<< "\n%s\n"<< FindFileData1.cFileName <<endl;
cout<< "%S\n" << FindFileData1.cAlternateFileName <<endl;
}
}
}
while( FindNextFile( hFind, &FindFileData ) );

FindClose(hFind);



havn't compiled it so i can't promise anything but give it a shot (it will recurse through sub directories t0o.

~guyaton

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
I would use boost::filesystem.


hmm, looks a bit heavy for what i want to do, also seems that the library will need to be rebuilt for every platform ... thats what i was trying to avoid ...

Quote:
Original post by guyaton
There is a windows specific way if you want.
it looks like this:

*** Source Snippet Removed ***

havn't compiled it so i can't promise anything but give it a shot (it will recurse through sub directories t0o.

~guyaton


thanks, that will work for windows ...

i guess that this just isn't something that can be done without relying on a specific system API, or including more libraries in my application ... thanks anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Malchivus
seems that the library will need to be rebuilt for every platform ... thats what i was trying to avoid ...

I fail to see why that would be a problem since you need to rebuild your application for every platform. Also you don't need to build boost as a library. It's perfectly feasible to add the four or five source files that go into making up boost::filesystem as source files in your application.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sicrane..you worship boost don't you?..lol

Share this post


Link to post
Share on other sites
Quote:
Original post by Malchivus
Quote:
Original post by SiCrane
I would use boost::filesystem.


hmm, looks a bit heavy for what i want to do, also seems that the library will need to be rebuilt for every platform ... thats what i was trying to avoid ...


Given that there is no standard API that will work on every system you will have to rely on a third party library. If you're not interested in using Boost, you can use the Apache Portable Runtime instead.

Having to rebuild the library is really a minor issue when compared to the need to rewrite and rebuild your code.

Quote:
Original post by Anonymous Poster
sicrane..you worship boost don't you?..lol


It works, provides a lot of widely needed facilities... why not use it? I see nothing wrong with that.

Share this post


Link to post
Share on other sites
i didn't understand that there was no prtable way to do it. i thought that somewhere burried in gcc(mingw) there would be something. oops

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!