Hi, I am trying to create a simple program to rename a bunch of files

    #include <stdio.h>

    int main(){

        int count;

        for(count = 1; count <= 95; count++){

            if(count >= 10){
            system("rename \"C:\\wamp\\www\\anime\\kenshin\\Rurouni Kenshin - %d.mkv\" \"%d.mkv\"", count, count);

            /* For the episodes that have 0 before the number e.g 01..09 */
            system("rename \"C:\\wamp\\www\\anime\\kenshin\\Rurouni Kenshin - %d%d.mkv\" \"%d.mkv\"", 0, count, count); 

    return 0;

I keep on receiving the "The system cannot find the file specified." message when I run it but I know it is the right path. I have tried using the rename() function but it tells me that I have "too many actual parameters".. Can someone help a newbie out?

5 Years
Discussion Span
Last Post by CelestialTeapot

You have to format the string with sprintf() before passing it to system() or rename() functions -- those functions don't work like printf().


/* For the episodes that have 0 before the number e.g 01..09 */

That's not necessary. Just use "%0.2d" and the number will have 0 before the first digit if there is only 1 digit.
char buf[50];
sprintf(buf,"\"C:\wamp\www\anime\kenshin\Rurouni Kenshin - %0d.mkv\" \"%d.mkv\"", count, count);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.