getting in a string content of a folder
karistouf

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

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 ...

Rampage

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);

karistouf

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
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.

Goalie Ca

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.

CGamesPlay
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.

Goalie Ca

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.

karistouf

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

HoHo
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

CGamesPlay
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.

Thread #590518. Printed from Allegro.cc