Results 1 to 2 of 2
Hi..I've got a program that can list the directories and files
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#define REQUEST_DIR "/"
int main(int argc, char *argv[]){
FILE *fp;
DIR ...
- 07-02-2009 #1Just Joined!
- Join Date
- Jun 2009
- Posts
- 20
Removing Directories from a LINUX server recursively
Hi..I've got a program that can list the directories and files
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#define REQUEST_DIR "/"
int main(int argc, char *argv[]){
FILE *fp;
DIR *dirp;
struct dirent *dp;
struct stat buf;
dirp = opendir(REQUEST_DIR);
chdir(REQUEST_DIR);
/* Look at each entry in turn */
while ((dp = readdir(dirp)) != NULL) {
/* Now stat the file to get more information */
if (stat(dp->d_name, &buf) == -1)
perror("stat\n");
if (S_ISDIR(buf.st_mode))
printf("%s is a directory\n", dp->d_name);
else if (S_ISREG(buf.st_mode))
printf("%s is a regular file\n", dp->d_name);
}
(void) closedir(dirp);
}
I need to construct a recursive function to the directories recursively and delete it if it matches the parent directory.......any help as soon as possible pls....I'm quite a beginner to C
- 07-02-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
This is a class exercise?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote