Inhalt eines Verzeichnis anzeigen

Post Reply
Message
Author
Phil

Inhalt eines Verzeichnis anzeigen

#1 Post by Phil »

Hallo!

Wie kann ich den Inhalt eines Verzeichnisses lesen und am Monitor ausgeben??

Danke

Phil

neek

Re: Inhalt eines Verzeichnis anzeigen

#2 Post by neek »

hi,

versuchs doch mal mit

system ("dir");

bis dann

neek

User avatar
heinrich
Posts: 219
Joined: 22. Sep 1999 11:22
Location: N49.137 E8.544

Re: Inhalt eines Verzeichnis anzeigen

#3 Post by heinrich »

Sources:
<a href="http://www.home.fh-karlsruhe.de/~geth00 ... nux.tar.gz" target="_blank"><!--auto-->http://www.home.fh-karlsruhe.de/~geth00 ... <!--auto-->

Beispiel:<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2"><font size="2">
#include <iostream> // cout
#include <sys/types.h>
#include <dirent.h>

using namespace std;

void list_directory(char* path);

//-----------------------------
int main(int argc, char **argv)
//-----------------------------
{
char* dir_path = (argc>1) ? *++argv : "." ;

list_directory(dir_path);

return 0;
}

//-----------------------------
void list_directory(char* path)
//-----------------------------
{
DIR *Verzeichnis;
struct dirent *VerzEintrag;

Verzeichnis = opendir(path);

VerzEintrag = readdir(Verzeichnis);
while ( VerzEintrag != NULL )
{
cout << VerzEintrag->d_ino << " "
<< VerzEintrag->d_name << endl;
VerzEintrag = readdir(Verzeichnis);
}

closedir(Verzeichnis);
}
</font><hr></pre></blockquote>
Last edited by heinrich on 22. Dec 1999 21:01, edited 1 time in total.

Post Reply