diff options
| author | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-02-25 18:15:43 +0100 |
|---|---|---|
| committer | Abdellah El Morabit <nsrddyn@gmail.com> | 2025-02-25 18:15:43 +0100 |
| commit | e20e3f22e9218dc99cf7609687051669b9c445ae (patch) | |
| tree | 6e5c3f1105d95179c1412118017ea88116ce19be | |
| parent | 7945d8b6870dcdf27e0cf2daaafe1252822d862d (diff) | |
dont know what i am even doing at this point, getting a segmentation fault while trying to delete an emty folder...
| -rwxr-xr-x | a.out | bin | 51736 -> 51736 bytes | |||
| -rw-r--r-- | folder/file1 | 0 | ||||
| -rw-r--r-- | main.c | 25 |
3 files changed, 16 insertions, 9 deletions
| Binary files differ diff --git a/folder/file1 b/folder/file1 deleted file mode 100644 index e69de29..0000000 --- a/folder/file1 +++ /dev/null @@ -6,6 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> +#define AUTHOR "ABDELLAH EL MORABIT" + #define MAX_HISTORY 100 #define MAX_COMMAND_LENGTH 255 // not setting a macro for the argument because they are included in the command #define MAX_PATH_LENGTH 1024 @@ -147,33 +149,38 @@ void list(const char *path) { void remove_dir(const char *path) { if (rmdir(path) != 0) { - perror("failed to delete the directory"); - } else { + printf("directory not empty"); + } + else { struct dirent *entry; // cant be a const because inserting it into the readdir functions causes a warning becasue it expects a non const dir variable - DIR *dP = opendir(path); + DIR *dP = opendir("/"); + printf("opended the directory"); if (dP == NULL) { perror("failed to open the directory to delete the files recursively"); } - // ReSharper disable once CppPointerConversionDropsQualifiers - while ((entry = readdir(dP)) != NULL && (strcmp(entry->d_name, ".") != 0) && ( - strcmp(entry->d_name, "..") != 0)) { - if (rmdir(entry->d_name) != 0) { + while ((entry = readdir(dP)) != NULL && rmdir(path) != 0){ + if (strcmp(entry->d_name, "." ) == 0 || strcmp(entry->d_name, "..")== 0){ + printf("%p",entry->d_name); + continue; + } + else if (remove(entry->d_name) != 0) { + printf("%p", entry->d_name); perror("failed to delete the directory 02"); } } printf("%p", dP); + closedir(dP); } } void make_dir(const char *path) { - if (mkdir(path, 0755) == 0) + if (mkdir(path, 0755) != 0) perror("failed to make directory"); } - void remove_file(const char *path) { if (remove(path) != 0) { perror("failed to delete file"); |
