// Changer.vdm // based on code provided in Code Center at http://www.pinc.com/~slambert // template for a macro that needs to process multiple files in a directory // and optionally it's subdirectories // supports wildcards - assumes all files unless otherwise specified // text register 10 holds the directory path - ie c:\letters // text register 11 holds the filespec - ie *.doc // numeric register #10 holds the "included subdirectories ?" flag : 0=no 1=yes // text register 20 holds current directory path ie c:\letters // text register 21 holds current filename ie moremoney.doc // text register 22 holds the whole path and filename of current file ie c:\letters\moremoney.doc // numeric register #30 holds starting buffer # // numeric register #31 holds buffer # of temp buffer for dir listing // initialize registers #30=buf_num // save current buffer # #31=buf_free // find a free buffer to hold dir listing #10=0 // set include subdirectories flag to no reg_set(40,"c:\vedit") // folder where to find search / replace files // get user input get_input(10,"Enter Directory Path = ",nocr+statline) // get directory path get_input(11,"Enter FileSpec = ",nocr+statline) // get filespec if(reg_size(11)==0) {reg_set(11,"*.*")} // if no filespec, assume *.* #10=get_num("Include Subdirectories ? 0=no 1=yes : ") // ask about subdirectories // get directory listing buf_switch(#31) // switch to temp buffer buf_empty(ok) // empty it file_save_as("c:\dirlist.tmp",nomsg+ok) // give it a filename to enable auto-buffering reg_set(30,@10) // set t-reg 30 to directory path reg_set(30,"\",append) // add a \ reg_set(30,@11,append) // add the filespec in t-reg 11 if(#10==1) {reg_set(30," -s",append)} // add the -s if subdirectory flag is set out_ins() // re-direct output to temp buffer directory(@30,suppress+count,1) // dump dir, one column, no subdir or hidden names out_ins(clear) // turn off output re-direct begin_of_file() // goto start of buffer repeat(all) { // repeat loop 1 // get directory path search("Directory ",advance+noerr) // search for word Directory if(return_value==0) {break} // didn't find it, exit repeat loop 1 block_begin(cur_pos) // set block begin to current position block_end(eol_pos) // set block end to end of line postion reg_copy_block(20,block_begin,block_end) // shove directory path into t-reg 20 repeat(all) { // repeat loop 2 // get a filename goto_line(cur_line+1) // goto start of next line match("|F") // match letter or digit if(return_value<>0) { // if no filename on current line, do break // exit repeat loop 2 } // end of if block_begin(cur_pos) // set block begin to current position block_end(eol_pos) // set block end to end-of-line postion reg_copy_block(21,block_begin,block_end) // shove filename into t-reg 21 reg_set(22,@20) // set t-reg 22 to current dir path reg_set(22,"\",append) // add a \ reg_set(22,@21,append) // add current filename buf_switch(#30) // switch back to original buffer //-------------------------------------------------------------------------- // start of user's code to process filename in t-reg 22 // do not alter text or numeric registers in the range of 10 to 39 buf_empty(ok) file_open(@22) #40=1 repeat(all) { buf_switch(33) // switch to temp buffer buf_empty(ok) // empty buffer num_ins(#40,left+nocr) // insert n-reg 40, left justified, no newline characters #41=cur_pos // save end of number file position begin_of_file() // goto start of buffer block_begin(cur_pos) // set block begin at start of number block_end(#41) // set block end at end of number reg_copy_block(41,block_begin,block_end) // copy block to t-reg 41 buf_switch(#30) // return to original buffer #50=0 reg_set(42,@40) reg_set(42,"\search",append) reg_set(42,@41,append) reg_set(42,".txt",append) file_exist(@42,suppress+noerr) if(return_value==0) {break} reg_set(43,@40) reg_set(43,"\replace",append) reg_set(43,@41,append) reg_set(43,".txt",append) file_exist(@43,suppress+noerr) if(return_value==0) {break} begin_of_file() reg_load(44,@42) reg_load(45,@43) replace(@44,@45,all+noerr) #40=#40+1 } // end of repeat loop file_save(nomsg) // end of user's code //-------------------------------------------------------------------------- buf_switch(#31) // switch back to temp buffer } // end of repeat loop 2 } // end of repeat loop 1 // macro shutdown buf_switch(#31) // switch to temp buffer buf_quit(ok) // kill it buf_switch(#30) // goto original buffer file_delete("c:\dirlist.tmp",ok+noerr) // delete temp file block_begin(clear) // clear any stray block markers update() // update screen - end of macro