RegRen
This is a useful little utility that searches through directory trees recursively matching files (or directory names) with a regular expression. It then creates batch files for you to case shift the file names or execute arbitrary commands on them.Contact Info:
By Shannon Larratt
http://glider.bmezine.com/
No warranties
Public domain
Open sourceDownload it:
Windows EXE file
PBCC BAS file (source code, very sloppy)Usage:
This is a command line utility. Execute it from the directory you'd like to search. The current directories and all below it will be searched.
RegRen [regex] u|l|r|c ["command"] [-opt] [-opt] [> file.ext][regex] is optional. It is a regular expression. For example, ".*\.html" matches all files ending in ".html", and "[a-z][0-9]+" matches all files with no extension starting with a single letter and finishing with one or more numbers. See the section on regular expressions for more information. If you do not ever a regex, ".*" will automatically be used (ie. "all files").
u|l|r|c These are your commands. You have to have to pick one:
u Convert all matches to uppercase (unless they already are).[-d] This option tells the program to search for directories rather than files.l Convert all matches to lowercase.
r Do a regex based renaming. The replace follows ["command"], and should be entered in the form "old with new". For example "~~ with _" would replace all word spaces with an underscore character. To give a more complex example, "([a-z~~_-]+)(\.htm[l]?) with HTML:\01" would rename all files ending in either ".htm" or ".html" with "HTML:filename" with the extension removed. Note that for the purposes of this tool, ~~ (two tilde characters) are used to represent a space.
c Execute a custom command. The command follows ["command"], although you can leave it off to simply output a list of all matches. If you do elect to enter a command, type in what you'd like the batch file to execute, with "*file*" representing the filename. For example, "notepad *file*" would load all the matches into notepad, and "copy *file* a: /A" would copy all matches to your floppy drive, with the file mode set to ASCII.
[-c] If operating in file mode, the software will by default insert a chdir command whenever needed, and operate in local mode. If you use the -c option, these are suppressed and files are referred to in absolute terms.
[-q] If you select this option, quotes will be placed around all file and directory names. By default they will only be palced around structures with spaces in them.
[-l] By default RegRen maxxes out at 50,000 files. By selecting this (large mode), it will max out at 250,000 files instead.
[-g] This increases the processing array to a maximum size of 1,000,000 elements (note that processing directory structues this large can be time consuming!).
[-i] If you select this option the softare will include debugging type information in its output. If you're generating a batch file you will need to edit it out before executing.
[> file.ext] If you type this, the output will of course be written to that file. If you don't, it'll be displayed on the screen — RegRen never executes any of the commands; it just generates the batch files to let you do so.
(Note: the [ and ] characters are there to indicate the item is optional. Don't actually type them!)
Regular Expressions:
. (period) matches any character except the end-of-line.
^ (caret) matches the beginning-of-line position.
$ (dollar) matches the end-of-line position, but line delimter characters (cr/lf) are not included with the returned text.
| (pipe) specifies alternation (the OR operator), so that an expression on either side can match – precedence is left-to-right as encountered in the expression.
? (question mark) specifies that zero or one match of the preceding sub-pattern is allowed.
+ (plus) specifies that one or more matches of the preceding sub-pattern are allowed.
* (asterisk) specifies that zero or more matches of the preceding sub-pattern are allowed.
[ ] (square brackets) identifies a class of characters, any of which will match: [abc] will match a, b, or c.
[^] identifies a complemented class or characters, which will not match: [^abc] matches any character except a, b, or c.
[-] identifies a range of characters to match: [a-f] will match a, b, c, d, e, or f. [f-a] matches nothing. Special interpreted characters (\t, \f, \x, etc.) may not be used in a range).
( ) (parenthesis) used to match a Tag, or sub-pattern, within the full search pattern, and remember the match. The matched sub-pattern can be retrieved later in the mask, or in a replace operation, with \01 through \99, based upon the left-to-right position of the opening parenthesis. Parenthesis may also be used to force precedence of of evaluation with the alternation operator. For example, "(Begin)|(End)File" would match either "BeginFile" or "EndFile", but without the Tag designations, "Begin|EndFile" would only match either "BeginndFile" or "BegiEndFile". Parenthesis can not be used with the ?, +, or * operators.
\ (backslash) escape operator, marks the next character as either a special character or a literal. For example, "n" matches the character "n" while "\n" matches a newline character. "\\" matches "\" and "\(" matches "(".
\b interpreted as a word boundary. A word is considered one or more characters that include an alphabetic character (A-Z or a-z), a numeric character (0-9) and an underscore. For example, "abc_123" is considered a single word and "abc-123" is considered two words.
\c forces case-sensitive search – must be the first option in the search mask. Unlike some limited implementations of regular expressions, case-insensitivity is recognized in all operations, even a range of characters such as "[6-Z]".
\q interpreted as a double quote (") for ease of inclusion in a literal string with source programs.
\x interpreted as an evaluated character code in hex, defined by the two following hex digits: \xFF = ASCII 255.
\## evaluated as the characters matched by tag number ## (## could be 01 through 99). Tags are implicitly numbered from 01 through 99 based upon the left-to-right position of the left parenthesis. "(…)w\01" would match "abcwabc" or "456w456". If a reference is made to any Tag that is not yet defined, a non-match is presumed.Enjoy!