#include "rename.h"
#include "config.h"
-void rename_files(const char* dir_path, rename_func_ptr renamefunc)
+glob_t* get_files(const char* dir_path)
{
glob_t* files = malloc(sizeof(glob_t));
- struct stat* statbuf = malloc(sizeof(struct stat));
-
char* pattern = malloc(sizeof(char) * strlen(dir_path) + 3);
+
+ sprintf(pattern, "%s/*", dir_path);
+ glob(pattern, 0, NULL, files);
+
+ free(pattern);
+ pattern = NULL;
+ return files;
+}
+
+void rename_files(const char* dir_path, rename_func_ptr renamefunc)
+{
+ struct stat* statbuf = malloc(sizeof(struct stat));
char* input_filename = malloc(sizeof(char) * STR_MAX_LENGTH);
memset(input_filename, 0, STR_MAX_LENGTH);
char* output_filename = malloc(sizeof(char) * STR_MAX_LENGTH);
memset(output_filename, 0, STR_MAX_LENGTH);
- sprintf(pattern, "%s/*", dir_path);
- glob(pattern, 0, NULL, files);
+ glob_t* files = get_files(dir_path);
for (int i = 0; i < files->gl_pathc; i++) {
stat(files->gl_pathv[i], statbuf);
files = NULL;
free(statbuf);
statbuf = NULL;
- free(pattern);
- pattern = NULL;
free(input_filename);
input_filename = NULL;
free(output_filename);