-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmfiles.cpp
More file actions
53 lines (40 loc) · 972 Bytes
/
rmfiles.cpp
File metadata and controls
53 lines (40 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <cstring>
#include <unistd.h>
using namespace std;
const char* arg0;
#define USAGE "Usage: %s <filelist-filename>\n"
int main(int argc, const char* argv[])
{
arg0 = argv[0];
FILE* stream;
char line[PATH_MAX+2];
if (argc != 2)
{
fprintf(stderr, USAGE, arg0);
exit(1);
}
const char* filename = argv[1];
if (!(stream = fopen(filename, "rb")))
{
fprintf(stderr, "%s: cannot open: %s\n", arg0, filename);
exit(1);
}
while(fgets(line, sizeof(line), stream) != NULL)
{
char* p = line + strlen(line);
while (p != line && isspace(p[-1]))
*--p = '\0';
printf("Removing %s...\n", line);
if (unlink(line) < 0)
{
fprintf(stderr, "%s: failed to remove: %s\n", arg0, line);
exit(1);
}
}
fclose(stream);
return 0;
}