-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_list.c
92 lines (75 loc) · 1.75 KB
/
dir_list.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include "dir_list.h"
struct dir_list
{
char current_directory[1024];
int indent;
int file_count;
};
dir_list* dir_list_construct_obj(void)
{
dir_list* instance = malloc(sizeof(dir_list));
if (instance == NULL) {
puts("dir_list object could not be created.");
}
return instance;
}
void dir_list_get_files(dir_list* this, char files[100][30])
{
DIR *d;
struct dirent *dir;
d = opendir(".");
if (d)
{
int file_count = 0;
while ((dir = readdir(d)) != NULL)
{
strcpy(files[file_count], dir->d_name);
file_count++;
}
this->file_count = file_count;
while (file_count < 100) {
strcpy(files[file_count], "UNUSED_FILE_INDEX");
file_count++;
}
for (int i = 0; i < 100; i++) {
if (strcmp(files[i],"UNUSED_FILE_INDEX") != 0) {
//printf("%s\n", files[i]);
}
}
closedir(d);
}
}
// int dir_list_get_file_count()
// {
// int count = 0;
// }
void dir_list_set_indent(dir_list* list, int indent)
{
if (&indent == NULL)
{
return;
}
list->indent = indent;
}
int dir_list_get_indent(dir_list* this)
{
return this->indent;
}
int dir_list_get_file_count(dir_list* this)
{
return this->file_count;
}
void dir_list_delete_obj(dir_list* obj) {
free (obj);
}
void dir_list_set_current_directory(dir_list* list, char directory[1024]) {
//list->current_directory = directory;
memcpy(list->current_directory, directory, 1024);
}
char* dir_list_get_current_directory(dir_list* this) {
return this->current_directory;
}