From d82f98e5d87162c77bc3472afa45411610f4d336 Mon Sep 17 00:00:00 2001 From: luca0N! <63941044+luca0N@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:53:08 -0300 Subject: [PATCH] Added delete routine --- main.c | 22 ++++++++++++++++++++-- str.h | 5 +++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index f191aa5..e529a7f 100644 --- a/main.c +++ b/main.c @@ -64,10 +64,15 @@ void getAdditionalDirs(){ } void cleanDir(const char* path){ - printf("%s %s\n", STR_CLEANING_DIR, path); + // Path with wildcard + char wildPath[strlen(path) + 1]; + strcpy(wildPath, path); + strcat(wildPath, "*"); + + printf("%s %s\n", STR_CLEANING_DIR, wildPath); // Fetch files in dir WIN32_FIND_DATA data; - HANDLE hFind = FindFirstFile(path, &data); + HANDLE hFind = FindFirstFile(wildPath, &data); unsigned int iteration = 0; if (hFind != INVALID_HANDLE_VALUE){ do{ @@ -76,6 +81,19 @@ void cleanDir(const char* path){ if (iteration <= 2) continue; printf("%s %s\n", STR_FOUND_ITEM, data.cFileName); + // Attempt to delete file... + + int pathSize = strlen(wildPath) + strlen(data.cFileName); + char fullPath[pathSize]; + strcpy(fullPath, path); + strcat(fullPath, data.cFileName); + + if (DeleteFile(fullPath) == 0){ + printf(" %s\n", STR_FAILED_FILE); + printf(" --> %s\n", fullPath); + printf(" --> %#010x\n", GetLastError()); + } else + printf(" %s\n", STR_DELETED_FILE); } while(FindNextFile(hFind, &data)); } else { printf("%s\n", STR_FAILED_DIR_LIST); diff --git a/str.h b/str.h index a9a6bdc..c89b157 100644 --- a/str.h +++ b/str.h @@ -27,13 +27,14 @@ #define STR_FETCHING_ADD_DIRS "Recolhendo pastas adicionais..." #define STR_CLEANING_DIR "[Limpando pasta]" -#define STR_REMOVED_FILE "[Arquivo removido]" -#define STR_REMOVED_DIR "[Pasta removida]" +#define STR_DELETED_FILE "[Arquivo removido]" +#define STR_DELETED_DIR "[Pasta removida]" #define STR_DIR_COUNT "[Contagem de pastas]" #define STR_FOUND_DIR "[Pasta encontrada]" #define STR_FOUND_FILE "[Arquivo encontrado]" #define STR_FOUND_ITEM "[Item encontrado]" #define STR_FAILED_DIR_LIST "Um erro ocorreu ao tentar enumerar os arquivos dentro de uma pasta especificada." +#define STR_FAILED_FILE "[Arquivo mantido] Não foi possível remover este arquivo pelo seguinte erro:" #define STR_ERROR_LIC "Falha ao ler arquivo de licença. Visite para mais informações."