]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
change rename file extra method
authorBastian Dehn <hhaalo@arcor.de>
Thu, 2 Oct 2025 08:22:22 +0000 (10:22 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 2 Oct 2025 08:22:39 +0000 (10:22 +0200)
src/main.c

index 3c4408e8228310a9be0180f13de79cb80b67efbd..2e2f0b482013aa1ce0bbc1d2996cc13faa8dd8ff 100644 (file)
@@ -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);