-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindowsccleaner.c
52 lines (45 loc) · 1.31 KB
/
windowsccleaner.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
50
51
52
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
int main() {
printf("Welcome to diskclean. This Program works in Windows 10 and 11\n");
printf("All opened Programs should be closed before you continue\n");
printf("When the program has finished, 'ready' will be shown.\n");
printf("Press 'c' key to continue...\n");
while (1) {
if (_kbhit()) {
char ch = _getch();
if (ch == 'c') {
break;
}
}
}
const char *tmp_path = "C:\\Windows\\Temp";
struct dirent *entry;
DIR *dp = opendir(tmp_path);
if (dp == NULL) {
perror("opendir");
return EXIT_FAILURE;
}
while ((entry = readdir(dp)) != NULL) {
char file_path[512];
snprintf(file_path, sizeof(file_path), "%s\\%s", tmp_path, entry->d_name);
if (entry->d_type == DT_REG) {
FILE *file = fopen(file_path, "r+");
if (file) {
fclose(file);
continue; // File is still in use
}
if (remove(file_path) == 0) {
printf("Deleted: %s\n", file_path);
} else {
perror("remove");
}
}
}
closedir(dp);
return EXIT_SUCCESS;
}