Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » getting in a string content of a folder

This thread is locked; no one can reply to it. rss feed Print
getting in a string content of a folder
karistouf
Member #5,126
October 2004
avatar

hello, is there any elegant way to get the equivalent of system("dir *./b/w > list_of_shows.txt ") then get the text inside of a string ? :o

using external command of system ( winXP) I m enclenching and flashing a dos window...
I was thinking to do something like tree>my_string, but commands like dir or tree seems not existing in gcc ???

thanks for the answer !!! :P

Michael Faerber
Member #4,800
July 2004
avatar

If you're using Allegro, you might consider using these functions.

[EDIT]
Heh, you are lazy ... you didn't even search for your problem! This was the thread below your one ...

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

Rampage
Member #3,035
December 2002
avatar

This is not elegant nor equivalent, but might be enough.

FILE *f = NULL;
char line[256] = "";
char dir_result[4096] = "";
system("dir c:\\my_path\\ > c:\\file.txt");
f = fopen ("C:\\file.txt", "r");
while (fgets(line, 256, f) != NULL) {
  strcat(dir_result, line);
}
fclose(f);

printf(dir_result);

-R

karistouf
Member #5,126
October 2004
avatar

yes, I m under allegro ( so i m not using system command because they flash shortly the ms dos screen on my app).
in fact, is there any key word for just having list of folder types inside a folder ?

( thanks for your answer!);D

Matthew Dalrymple
Member #7,922
October 2006
avatar

Quote:

is there any key word for just having list of folder types inside a folder

FA_DIREC?

al_findfirst("*", &info, FA_DIREC);

Were you asking how to just see the folders? Above + al_findnext gives you the directories.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Goalie Ca
Member #2,579
July 2002
avatar

Can someone explain why such a thing is not part of standard c++ (though most cross-platform libraries end up including such functionality). This is a really common task.

-------------
Bah weep granah weep nini bong!

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

Can someone explain why such a thing is not part of standard c++ (though most cross-platform libraries end up including such functionality). This is a really common task.

Sure: It's a command task on PCs, but that's not what C++ was designed for.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Goalie Ca
Member #2,579
July 2002
avatar

I was thinking about the scope of C++ and its embedded stuff (Since i deal with that too) and embedded systems actually deal a lot with files as well. It's really just one of those things that has some obscure bs reason or it could be as simple as no one has bothered yet.

-------------
Bah weep granah weep nini bong!

karistouf
Member #5,126
October 2004
avatar

thanks to evey body for the answer, always a pleasure!!!

HoHo
Member #4,534
April 2004
avatar

Quote:

Can someone explain why such a thing is not part of standard c++

This is a common part of C and C is part of C++ so you have this functionality readily availiable in C++ too.
http://www.gnu.org/software/libc/manual/html_node/File-System-Interface.html#File-System-Interface

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

embedded systems actually deal a lot with files as well.

Some do, but even in those it's not uncommon to have a radically different file system than the PC one, which makes it impossible to design a unified interface to.

Of course, it occurs to me know that I'm confusing C++ and the standard library. Sooo, I suppose a better reason is simply that Microsoft didn't think it was worthwhile to implement the functions in HoHo's link.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Go to: