REBOL [ Title: "REBOL rename" Date: "March 2003" Name: "rename" Version: 0.1 File: "rebname" Author: "Trevor Gosbell" Owner: "Trevor Gosbell" Rights: "Open to MelbPC members" Usage: {rebol rename "find-pattern" ["replace-pattern"]} Purpose: {For all file names in the current directory, replaces find-pattern with replace-pattern. If replace-pattern is omitted, find-pattern is removed from the file names.} Comment: {It CHANGES FILE NAMES - use at your own risk!} ] ; retrieve command line arguments from the system object and convert to a block cl_args: make block! system/script/args ; if the first argument exists, assign it to the search term search_term: either none? cl_args/1 [""] [to-string cl_args/1] ; if the second argument exists, assign it to the replace term replace_term: either none? cl_args/2 [""] [to-string cl_args/2] ; change working directory to start up directory (change-dir system/options/path) ; read all of the filenames in working directory (read) ; loop through all of the files in the directory (foreach file) foreach file read change-dir system/options/path [ ; process files only, not directories if not dir? file [ ; only proceed with this file if the search term is found if not none? find file search_term [ ; make a new file name by replacing the search term with the replace term new_file: to-file replace to-string file search_term replace_term ; if the filename already exists, don't rename the current file either exists? new_file [ ; print a warning print ["FILENAME" new_file "ALREADY IN USE"] ] [ ; print notification print ["Renaming" file "to" new_file] ; rename the file (finally!) rename file new_file ] ] ] ] ; exit the REBOL environment when finished quit