- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int files_hidden = 0; int files_dirs = 0; int files_files = 0;
#define MEGA 1007
void nextDir(char *path, FILE *f, const char *verbose)
{
DIR *dir = opendir(path);
if(dir)
{
struct dirent *ent;
while((ent = readdir(dir)) != NULL)
{
if(strcmp(ent->d_name, ".") == 0) continue;
if(strcmp(ent->d_name, "..") == 0) continue; if(ent->d_name[0] == '.') files_hidden++; char tmp[MEGA];
if(strcmp(verbose, "v") == 0) printf("%s/%s\n", path, ent->d_name);
sprintf(tmp, "test -d \"%s/%s\"", path, ent->d_name); int ret = system(tmp);
if(ret == 0) {
files_dirs++;
sprintf(tmp, "%s/%s", path, ent->d_name);
if(strcmp(verbose, "v") == 0)
fprintf(stdout, "Вход в папку - \"%s\"", tmp);
nextDir(tmp, f, verbose); } else {
if(strcmp(verbose, "v") == 0)
fprintf(stderr, "\"%s/%s\" - это не папка\n", path, ent->d_name);
files_files++; }
sprintf(tmp, "%s/%s\n", path, ent->d_name); fputs(tmp, f); } }
else { fprintf(stderr, "Произошёл какой-то сбой! Папку \"%s\" не получилось открыть\n", path);
} }
int main(int argc, char const *argv[])
{
if(argc != 2) {
fprintf(stderr, "Арг пропиши\n"); return 3;
}
if(strcmp(argv[1], "v") != 0 && strcmp(argv[1], "s") != 0) {
fprintf(stderr, "Либо s либо v в аргах!\n"); return 4;
}
printf("Начинается сбор...\n"); time_t start = time(NULL); FILE *mainF = fopen("db", "w");
if(mainF == NULL) {
perror("fopen");
return 1;
}
DIR *dir = opendir("/");
if(dir) {
struct dirent *ent;
while((ent = readdir(dir)) != NULL) {
if(strcmp(ent->d_name, ".") == 0) continue; if(strcmp(ent->d_name, "..") == 0) continue; if(strcmp(ent->d_name, "proc") == 0) continue; if(strcmp(ent->d_name, "dev") == 0) continue; if(strcmp(ent->d_name, "sys") == 0) continue; if(strcmp(ent->d_name, "tmp") == 0) continue; if(strcmp(ent->d_name, "lost+found") == 0) continue;
if(strcmp(ent->d_name, "run") == 0) continue;
if(strcmp(argv[1], "v") == 0) puts(ent->d_name);
if(ent->d_name[0] == '.') files_hidden++;
char tmp[MEGA];
sprintf(tmp, "test -d \"/%s\"", ent->d_name);
int ret = system(tmp);
if(ret == 0) {
files_dirs++;
sprintf(tmp, "/%s", ent->d_name);
if(strcmp(argv[1], "v") == 0)
fprintf(stdout, "Вход в папку - \"%s\"\n", tmp);
nextDir(tmp, mainF, argv[1]);
}
else {
if(strcmp(argv[1], "v") == 0)