From 8e4a3f473ca8b893b4696593e401fa53f460dfb6 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 2 Oct 2025 10:22:22 +0200 Subject: [PATCH] change rename file extra method --- src/main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 3c4408e..2e2f0b4 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,15 @@ bool is_dir(const char* path) return isdir; } +void rename_file(const char* input, const char* output) +{ + if (strcmp(input, output) == 0) + return; + + printf("%s -> %s\n", input, output); + rename(input, output); +} + void rename_files(const char* dir_path, rename_func_ptr renamefunc) { char* input = malloc(sizeof(char) * STR_MAX_LENGTH); @@ -44,12 +53,9 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) for (int i = 0; i < files->gl_pathc; i++) { renamefunc(files->gl_pathv[i], output); - if (strcmp(files->gl_pathv[i], output) != 0) { - printf("%s -> %s\n", files->gl_pathv[i], output); - rename(files->gl_pathv[i], output); - } + rename_file(files->gl_pathv[i], output); - if (is_dir(files->gl_pathv[i])) { + if (is_dir(output)) { escape_str(output, input); rename_files(input, renamefunc); } @@ -60,7 +66,6 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) globfree(files); files = NULL; - free(input); input = NULL; free(output); -- 2.47.3