// Space Replace // Copyright 2002 © Robert Wallis // http://www.codetriangle.com // // The purpose of this program is to rename // windows files that have spaces with more // unix compatable files #include #include #include #ifndef bool #define false 0 #define true 1 #ifndef boolean typedef char bool; #else typedef boolean bool; #endif #endif void usage() { printf("Space Replace\nCopyright (C) 2002 Robert Wallis\nhttp:\\\\codetriangle.com\n"); printf("usage: sr [-r='_'] [-s=' '] filename\n"); printf(" REPLACE CHARACTER\n"); printf(" -s=' '\n"); // printf(" Source Character: the ' ' (space) character can be replaced with a source\n"); printf(" character of your choice. \' \' is the default source character\n"); printf(" -r='_'\n"); printf(" Destination Character: the _ (underscore) character can be replaced with a\n"); printf(" character of your choice. _ is the default replaced character\n"); printf("\n"); printf(" EXAMPLES\n"); printf(" sr \"Various Artists\"*.mp3\n"); printf(" renames all files that start with \"Various Artists\" and end\n"); printf(" with \".mp3\", Various_Artists*.mp3\n\n"); printf(" sr -r='Z' -s='T' bar.Test\n"); printf(" renames \"bar.Test\" \"bar.Zest\"\n\n"); printf(" sr -s='T' -r='Z' bar.Test\n"); printf(" renames \"bar.Test\" \"bar.Zest\"\n\n"); printf(" sr *\n"); printf(" renames all files (in the current directory) with spaces, to files with\n"); printf(" underscores\n"); exit(1); } int main(int argc, char* argv[]) { int i; // loop through argv variable int j; // loop inside string variable int offset; // which argv starts the list of files char* temp; // temporary filename char replace_char; // replace source_char with this character char source_char; // character to replace replace_char bool changes; // are there any changes in the filename? // no args = show usage // usage() has to be down here because of the 6 instruction EE bug if (argc == 1) { usage(); } // set defaults replace_char='_'; source_char=' '; temp=0; i=0; j=0; offset=1; // the 0th argument is the program name changes=false; // program argument for (i=1; ii+1) { // check for alternate replace character -r if (argv[i][1]=='r' || argv[i][1]=='R') { replace_char=' '; i = i + 1; // make sure we use up the next argv } // check for alternate source character -s else if (argv[i][1]=='s' || argv[i][1]=='S') { source_char=' '; i = i + 1; // make sure we use up the next argv } else { usage(); } } else { usage(); } // this ^ is a program argument not a filename offset = i + 1; } else { break; } } // replace the filenames for (i=offset; i