I’ve tried this:
if (argc > 2) {
int i;
for(i = 0; i < argc; i++) {
if(i != 0) {
rename_file(argv[i]);
}
}
}
if I pass in two file names only the first is renamed, whats wrong with this loop?
EDIT: Heres the rename_file function (it should work I think)
void rename_file(char const *filename) {
struct tm *clock;
struct stat attrib;
const char *dot = strrchr(filename, '.');
const char *ext = NULL;
if (dot && *dot) {
ext = dot + 1;
}
stat(filename, &attrib);
clock = gmtime(&(attrib.st_mtime));
char newname[250];
if (!ext) {
printf("ERROR: No File Extenstion");
} else {
sprintf(newname, "%02d_%02d_%02d.%s", clock->tm_mday, clock->tm_mon, clock->tm_year + 1900, ext);
}
rename(filename, newname);
}
Try this: