- 论坛徽章:
- 0
|
- int rm_rf_dir(char *src_path)
- {
- DIR *dp;
- struct dirent *dir;
- struct stat st;
- char file_path[312];
- char msg_string[350];
- if((dp = opendir(src_path)) == NULL)
- {
- sprintf(msg_string,"ERRORS|Delete last month IndexDB %s error.\n",src_path);
- writeLog(conf_data.Log_path,msg_string,1);
- return (-1);
- }
- else
- {
- while((dir = readdir(dp)) != NULL)
- {
- if ( (strcmp(dir->d_name,".")!=0) && (strcmp(dir->d_name,"..")!=0) )
- {
- sprintf(file_path,"%s/%s",src_path,dir->d_name);
- if((stat(file_path,&st))==0)
- {
- if(S_ISREG(st.st_mode))
- {
- remove(file_path);
- }
- else if(S_ISDIR(st.st_mode))
- {
- rm_rf_dir(file_path);
- rmdir(file_path);
- }
- }
- }
- }
- closedir(dp);
- return (0);
- }
- }
复制代码 自己写了一段递归删除文件夹下面的子目录及文件的代码(保留目录本身),哪位老大能指点一下怎样改成迭代。 |
|