#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
using namespace std;
//LINUX下历遍目录 opendir -> readdir -> closedir
// 打开 -> 读取 -> 关闭
void Getfilepath(const char *path, const char *filename, char *filepath)
{
strcpy(filepath, path);
if(filepath[strlen(path) - 1] != '/')
strcat(filepath, "/");
strcat(filepath, filename);
printf("path is = %s\n",filepath);
}
bool DeleteFile(const char* path)
{
DIR *dir;
struct dirent *dirinfo;
struct stat statbuf;
char filepath[256] = {0};
lstat(path, &statbuf);
if (S_ISREG(statbuf.st_mode))//判断是否是常规文件
{
remove(path);
}
else if (S_ISDIR(statbuf.st_mode))//判断是否是目录
{
if ((dir = opendir(path)) == NULL)
return 1;
while ((dirinfo &#
linux C/C++ 删除某个目录下的所有文件实例
最新推荐文章于 2024-05-22 11:11:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)