刚学习linux下的文件和目录函数,利用这些写个linux的rm -rf功能模块。希望大家多多点评!!!
#include<stdio.h>
#include<sys/types.h>
#include<dirent.h>
#include<stdlib.h>
void removedir(char* dir);
void removefile(char *name)//remove file and empty dir
{
DIR *d;
if ((d = opendir(name)) == NULL)
{
printf("file:%s is moved!\n", name);
unlink(name);
}
else if ((rmdir(name)) == 0)
printf("dir:%s is moved!\n", name);
else
{
printf("dir name:%s\n", name);
removedir(name);
}
}
void removedir(char* dir)//check the dir
{
struct dirent *dp;
DIR *d;
char bb[10