-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdupe_parse.c
49 lines (39 loc) · 1.07 KB
/
dupe_parse.c
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
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#define TABLES_DIR "/var/pfpb/tables/"
void sort_file(const char *filename) {
char command[512];
// Construct the sort command
snprintf(command, sizeof(command), "sort -u %s%s -o %s%s",
TABLES_DIR, filename, TABLES_DIR, filename);
// Execute the command
int ret = system(command);
if (ret != 0) {
fprintf(stderr, "Error sorting file: %s (return code: %d)\n", filename, ret);
}
}
void process_files(void) {
struct dirent *entry;
DIR *dp = opendir(TABLES_DIR);
if (dp == NULL) {
perror("opendir");
exit(EXIT_FAILURE);
}
while ((entry = readdir(dp)) != NULL) {
// Skip "." and ".."
if (entry->d_name[0] == '.') {
continue;
}
// Skip directories
if (entry->d_type == DT_DIR) {
continue;
}
// Call sort_file for each file
sort_file(entry->d_name);
}
closedir(dp);
printf("Processing Lists Complete.\n");
}