From 8e062a16546e3c0a1c0c18252967183a1a07a855 Mon Sep 17 00:00:00 2001 From: AkriliksKotya Date: Sun, 7 Dec 2025 23:38:57 +0500 Subject: [PATCH] added input directory and files scan --- main.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index e20a595..7a48412 100644 --- a/main.c +++ b/main.c @@ -1,32 +1,98 @@ #include #include +#include + +int *check_dir(int *arr, DIR *d, char *directory){ + int i = 0; + int j = 0; + // char label[100]; + // DIR *d; + struct dirent *dir; + d = opendir(directory); + printf("dirrrr %s %s\n", d); + if (d) { + while ((dir = readdir(d)) != NULL){ + char *name = dir->d_name; + printf("%s\n", name); + if (*name == '.'){ + printf("directory starts with .\n"); + } + else{ + i += 1; + if(i - 10 == 0){ + i = 0; + j += 1; + } + // printf("%i %i \n",i,j); + // printf("%s\n", dir->d_name); + // sprintf(label, "%d" ,dir->d_name); + // char *lll = label; + // return lll; + arr[0] = i; + arr[1] = j; + // printf("%i %i\n", i,j); + // printf("%i %i\n",arr[0],arr[1]); + } + // closedir(d); + } + } + return 0; +} static void app_activate (GtkApplication *app, gpointer *user_data){ - + int p[2]; + int g; + int i = 0; + int j = 0; + DIR *d; + struct dirent *dir; + char directory[100]; + scanf("%100[^\n]", &directory); + d = opendir(directory); GtkWidget *window = gtk_application_window_new (GTK_APPLICATION(app)); gtk_window_set_title (GTK_WINDOW (window), "File Manager"); gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); gtk_window_set_application(GTK_WINDOW(window),app); - GtkWidget* grid = gtk_grid_new(); - - for (int i = 0; i<2;i++){ - for (int j = 0; j<10;j++){ - GtkWidget* btn = gtk_button_new(); - gtk_grid_set_row_spacing(GTK_GRID (grid), 10); - gtk_grid_set_column_spacing(GTK_GRID (grid), 10); - gtk_grid_set_column_homogeneous(GTK_GRID (grid), TRUE); - gtk_grid_set_row_homogeneous(GTK_GRID (grid), TRUE); - char *label = "waht"; - gtk_button_set_label(GTK_BUTTON(btn),label); - gtk_grid_attach (GTK_GRID(grid), btn, j, i, 1,1); - gtk_widget_set_halign(btn, GTK_ALIGN_CENTER); - gtk_widget_set_valign(btn, GTK_ALIGN_CENTER); - gtk_window_set_child(GTK_WINDOW(window),grid); - printf("%i %i \n ",i,j); + check_dir(p, d, directory); + printf("%i %i\n",p[0],p[1]); + g = 10; + while ((dir = readdir(d)) != NULL && i <=p[1] && j < g){ + if (d) { + printf("directory names\n"); + char *name = dir->d_name; + printf("%s\n", name); + if (*name == '.'){ + printf("directory starts with .\n"); + } + else{ + if (i == p[1]){ + printf("i=10 g=p[0]\n"); + g = p[0]; + } + // char lablell[100]; + printf("set directory label\n"); + GtkWidget* btn = gtk_button_new(); + gtk_grid_set_row_spacing(GTK_GRID (grid), 10); + gtk_grid_set_column_spacing(GTK_GRID (grid), 10); + gtk_grid_set_column_homogeneous(GTK_GRID (grid), TRUE); + gtk_grid_set_row_homogeneous(GTK_GRID (grid), TRUE); + // sprintf(lablell, "" ,check_dir()); + gtk_button_set_label(GTK_BUTTON(btn),name); + gtk_grid_attach (GTK_GRID(grid), btn, j, i, 1,1); + gtk_widget_set_halign(btn, GTK_ALIGN_CENTER); + gtk_widget_set_valign(btn, GTK_ALIGN_CENTER); + j++; + if (j >= 9){ + j = 0; + i++; + } + } } } - + closedir(d); + printf("set child and present window"); + gtk_window_set_child(GTK_WINDOW(window),grid); gtk_window_present(GTK_WINDOW(window)); g_print("Started\n"); }