Hallo!
Wie kann ich den Inhalt eines Verzeichnisses lesen und am Monitor ausgeben??
Danke
Phil
Inhalt eines Verzeichnis anzeigen
Re: Inhalt eines Verzeichnis anzeigen
hi,
versuchs doch mal mit
system ("dir");
bis dann
neek
versuchs doch mal mit
system ("dir");
bis dann
neek
Re: Inhalt eines Verzeichnis anzeigen
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>
<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.