Added delete routine
This commit is contained in:
parent
a720fab4ba
commit
d82f98e5d8
22
main.c
22
main.c
|
@ -64,10 +64,15 @@ void getAdditionalDirs(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanDir(const char* path){
|
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
|
// Fetch files in dir
|
||||||
WIN32_FIND_DATA data;
|
WIN32_FIND_DATA data;
|
||||||
HANDLE hFind = FindFirstFile(path, &data);
|
HANDLE hFind = FindFirstFile(wildPath, &data);
|
||||||
unsigned int iteration = 0;
|
unsigned int iteration = 0;
|
||||||
if (hFind != INVALID_HANDLE_VALUE){
|
if (hFind != INVALID_HANDLE_VALUE){
|
||||||
do{
|
do{
|
||||||
|
@ -76,6 +81,19 @@ void cleanDir(const char* path){
|
||||||
if (iteration <= 2)
|
if (iteration <= 2)
|
||||||
continue;
|
continue;
|
||||||
printf("%s %s\n", STR_FOUND_ITEM, data.cFileName);
|
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));
|
} while(FindNextFile(hFind, &data));
|
||||||
} else {
|
} else {
|
||||||
printf("%s\n", STR_FAILED_DIR_LIST);
|
printf("%s\n", STR_FAILED_DIR_LIST);
|
||||||
|
|
5
str.h
5
str.h
|
@ -27,13 +27,14 @@
|
||||||
#define STR_FETCHING_ADD_DIRS "Recolhendo pastas adicionais..."
|
#define STR_FETCHING_ADD_DIRS "Recolhendo pastas adicionais..."
|
||||||
|
|
||||||
#define STR_CLEANING_DIR "[Limpando pasta]"
|
#define STR_CLEANING_DIR "[Limpando pasta]"
|
||||||
#define STR_REMOVED_FILE "[Arquivo removido]"
|
#define STR_DELETED_FILE "[Arquivo removido]"
|
||||||
#define STR_REMOVED_DIR "[Pasta removida]"
|
#define STR_DELETED_DIR "[Pasta removida]"
|
||||||
#define STR_DIR_COUNT "[Contagem de pastas]"
|
#define STR_DIR_COUNT "[Contagem de pastas]"
|
||||||
#define STR_FOUND_DIR "[Pasta encontrada]"
|
#define STR_FOUND_DIR "[Pasta encontrada]"
|
||||||
#define STR_FOUND_FILE "[Arquivo encontrado]"
|
#define STR_FOUND_FILE "[Arquivo encontrado]"
|
||||||
#define STR_FOUND_ITEM "[Item 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_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 <https://www.gnu.org/licenses/> para mais informações."
|
#define STR_ERROR_LIC "Falha ao ler arquivo de licença. Visite <https://www.gnu.org/licenses/> para mais informações."
|
||||||
|
|
||||||
|
|
Reference in New Issue