当前位置: 技术问答>linux和unix
用c++如何删除一个文件夹下的所有文件?
来源: 互联网 发布时间:2015-12-19
本文导语: 如题 在linux下,用c++删除一个文件夹下的所有文件,那位高手给段代码。 不能删除文件夹本身。 | The following sample program searches the current directory for each of the arguments supplied on the comm...
如题
在linux下,用c++删除一个文件夹下的所有文件,那位高手给段代码。
不能删除文件夹本身。
在linux下,用c++删除一个文件夹下的所有文件,那位高手给段代码。
不能删除文件夹本身。
|
The following sample program searches the current directory for each of the arguments supplied on the command line.
#include
#include
#include
#include
static void lookup(const char *arg)
{
DIR *dirp;
struct dirent *dp;
if ((dirp = opendir(".")) == NULL) {
perror("couldn't open '.'");
return;
}
do {
errno = 0;
if ((dp = readdir(dirp)) != NULL) {
if (strcmp(dp->d_name, arg) != 0)
continue;
(void) printf("found %sn", arg);
(void) closedir(dirp);
return;
}
} while (dp != NULL);
if (errno != 0)
perror("error reading directory");
else
(void) printf("failed to find %sn", arg);
(void) closedir(dirp);
return;
}
int main(int argc, char *argv[])
{
int i;
for (i = 1; i
#include
#include
#include
#include
static void lookup(const char *arg)
{
DIR *dirp;
struct dirent *dp;
if ((dirp = opendir(".")) == NULL) {
perror("couldn't open '.'");
return;
}
do {
errno = 0;
if ((dp = readdir(dirp)) != NULL) {
if (strcmp(dp->d_name, arg) != 0)
continue;
(void) printf("found %sn", arg);
(void) closedir(dirp);
return;
}
} while (dp != NULL);
if (errno != 0)
perror("error reading directory");
else
(void) printf("failed to find %sn", arg);
(void) closedir(dirp);
return;
}
int main(int argc, char *argv[])
{
int i;
for (i = 1; i