/* program to allow for wild card renaming of files */ #include #include #include static char obuf[50], nbuf[50], cmd[110]; main(argc,argv) int argc; char *argv[]; { int i, ip, ier, mode; char *pt; if(argc < 4) { fprintf(stderr,"rename files, changing oldstring to newstring within the names.\n"); fprintf(stderr,"syntax: renamer oldstr newstr file[s]\n"); fprintf(stderr," oldstr -> old substring within filenames\n"); fprintf(stderr," newstr -> new substring within filenames\n"); fprintf(stderr," files -> files to be renamed, wildcards valid.\n"); fprintf(stderr,"If oldstr = \\^ append newstr to beginning of filenames.\n"); fprintf(stderr,"If oldstr = \\$ append newstr to end of filenames.\n"); fprintf(stderr,"WARNING : existing files with same target name will be replaced.\n"); fprintf(stderr,"Example : Given \"file1.dat file2.dat file3.dat\",\n"); fprintf(stderr,"rename them all to \"file1.data file2.data file3.data\"\n"); fprintf(stderr,"Type the following : \"renamer dat data file?.dat\"\n"); fprintf(stderr,"tjmartin@anl.gov 10/15/97\n"); exit(1); } mode = 0; /* assume normal replace mode */ if(argv[1][0]=='^') mode = 1; /* use prepend mode */ if(argv[1][0]=='$') mode = 2; /* use append mode */ for(i=3; i 0) { perror("renamer error"); exit(errno); } } exit(0); }