Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <limits.h>
- #include <stdlib.h>
- #include <string.h>
- int main ( int argc, char * argv[] )
- {
- int retval=0;
- int len=0;
- char srcname[PATH_MAX+10];
- char dstname[PATH_MAX+10];
- FILE * srcfile;
- FILE * dstfile;
- if ( argc != 3 ) {
- fprintf(stderr, "massrename srcfile dstfile\n");
- exit(1);
- }
- srcfile=fopen(argv[1], "r");
- dstfile=fopen(argv[2], "r");
- if ( srcfile==NULL || dstfile==NULL ) {
- perror("fopen");
- exit(2);
- }
- while ( !feof(srcfile) && !feof(dstfile)) {
- if (NULL==fgets(srcname, PATH_MAX, srcfile) ) {
- break;
- }
- if (NULL==fgets(dstname, PATH_MAX, dstfile) ) {
- perror("fgets(dstname):");
- break;
- }
- len=strlen(dstname);
- dstname[len-1]='\0';
- len=strlen(srcname);
- srcname[len-1]='\0';
- if (0==strcmp(srcname,dstname))
- continue;
- if ( 0 != rename(srcname,dstname)) {
- retval++;
- perror("rename:");
- }
- }
- return retval;
- }
Add Comment
Please, Sign In to add comment