![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto copy for files from folder to folder upon instant writing | Bashar | UNIX for Advanced & Expert Users | 2 | 08-21-2008 03:44 PM |
| unix command to cound the number of files in a folder | manas6 | UNIX for Dummies Questions & Answers | 6 | 04-21-2008 09:03 AM |
| ftp a files from a folder | dineshr85 | Shell Programming and Scripting | 2 | 10-08-2007 02:51 AM |
| Viewing files of another unix server (in a folder) | Djaunl | UNIX for Dummies Questions & Answers | 3 | 07-20-2006 11:09 AM |
| How can i move data files from a server to unix folder | shah2 | Shell Programming and Scripting | 1 | 03-01-2004 06:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
You can do this in plain C, no C++ class madness required. Code:
// listdir.c
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct dirent *de=NULL;
DIR *d=NULL;
if(argc != 2)
{
fprintf(stderr,"Usage: %s dirname\n",argv[0]);
return(1);
}
d=opendir(argv[1]);
if(d == NULL)
{
perror("Couldn't open directory");
return(2);
}
// Loop while not NULL
while(de = readdir(d))
printf("%s\n",de->d_name);
closedir(d);
return(0);
}
For more details, see 'man 3 opendir', 'man 3 readdir', and 'man 3 closedir'. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|