DEFLNG a-z FUNCTION PBMAIN() cmd$ = TRIM$(COMMAND$) IF cmd$ = "" THEN STDOUT "RegRen" STDOUT "This software creates REGEX-based batch commands for file processing." STDOUT "by Shannon Larratt - glider.bmezine.com" STDOUT STDOUT "Usage: RegRen [regex] u|l|r|c [""command""] [-opt] [-opt]" STDOUT " regex = Regular expression to match (all files if omitted)" STDOUT " u = Command: convert matches to uppercase" STDOUT " l = Command: convert matches to lowercase" STDOUT " r = Command: Do regex rename" STDOUT " ""command"" = Regex to replace with regex, in form ""x with y""" STDOUT " c = Command: Execute command macro (or just list files if none)" STDOUT " ""command"" = Command string to execute; *file* is filename" STDOUT " -d = Option: Operate on directories, not filenames" STDOUT " -c = Option: Suppress CHDIR commands" STDOUT " -q = Option: Put quotes around names" STDOUT " -l = Option: Large mode (250,000)" STDOUT " -g = Option: Giant mode (1,000,000)" STDOUT " -i = Option: Output additional info" STDOUT " >file.ext = Output filename (ie. use piping)" EXIT FUNCTION END IF infomode = 0 IF INSTR(cmd$, "-i") > 0 THEN infomode = 1 reregex: regex$ = PARSE$(cmd$, " ", 1) IF regex$ = "u" OR regex$ = "l" OR regex$ = "c" OR regex$ = "r" THEN cmd$ = ".* " & cmd$ GOTO reregex END IF IF infomode = 1 THEN STDOUT "Processing Regex: " & regex$ rootdir$ = CURDIR$ IF infomode = 1 THEN STDOUT "Root dir: " & rootdir$ SELECT CASE PARSE$(cmd$, " ", 2) CASE "u" thisaction = 1 IF infomode = 1 THEN STDOUT "Action: Uppercase" CASE "l" thisaction = 2 IF infomode = 1 THEN STDOUT "Action: Lowercase" CASE "c" thisaction = 3 firstquote = INSTR(cmd$, """") secondquote = INSTR(firstquote+1, cmd$, """") IF secondquote > firstquote+1 THEN cmdstring$ = MID$(cmd$, firstquote + 1, secondquote - firstquote - 1) ELSE cmdstring$ = "*file*" END IF IF infomode = 1 THEN STDOUT "Action: Command """ & cmdstring$ & """" CASE "r" thisaction = 4 firstquote = INSTR(cmd$, """") secondquote = INSTR(firstquote+1, cmd$, """") IF secondquote > firstquote+1 THEN cmdstring$ = MID$(cmd$, firstquote + 1, secondquote - firstquote - 1) IF INSTR(cmdstring$, " with ") > 1 THEN reg1$ = TRIM$(PARSE$(cmdstring$, " with ", 1)) REPLACE "~~" WITH " " IN reg1$ reg2$ = TRIM$(PARSE$(cmdstring$, " with ", 2)) REPLACE "~~" WITH " " IN reg2$ END IF IF reg1$ = "" OR reg2$ = "" THEN STDOUT "Error: ""regex with regex"" string appears incomplete or corrupted" EXIT FUNCTION END IF ELSE STDOUT "Error: ""regex with regex"" string not found" EXIT FUNCTION END IF IF infomode = 1 THEN STDOUT "Action: RegRepl """ & reg1$ & """ with """ & reg2$ & """" END SELECT IF INSTR(cmd$, "-d") > 0 THEN filemode = 2 IF infomode = 1 THEN STDOUT "Mode: Directory" ELSE filemode = 1 'directory mode IF infomode = 1 THEN STDOUT "Mode: File" END IF IF INSTR(cmd$, "-c") > 0 THEN includechdir = 2 IF infomode = 1 THEN STDOUT "ChDir: Suppressed" ELSE includechdir = 1 'chdir? IF infomode = 1 THEN STDOUT "ChDir: Included" END IF IF INSTR(cmd$, "-q") > 0 THEN quotemode = 1 IF infomode = 1 THEN STDOUT "Quotes: On" ELSE quotemode = 0 'quotes? IF infomode = 1 THEN STDOUT "Quotes: Off" END IF arraysize = 50000 IF INSTR(cmd$, "-l") > 0 THEN arraysize = 250000 IF INSTR(cmd$, "-g") > 0 THEN arraysize = 1000000 IF infomode = 1 THEN STDOUT "Array size: " & FORMAT$(arraysize, ",") IF MID$(rootdir$, 2, 1) = ":" THEN CHDRIVE LEFT$(rootdir$, 1) END IF CHDIR rootdir$ SHELL "cmd /c dir /s > regren.tmp" DIM filelist$(1 TO arraysize) numfiles = 0 potfiles = 0 numdir = 0 currentdir$ = "" OPEN "regren.tmp" FOR INPUT AS #1 DO UNTIL EOF(1) LINE INPUT #1, x$ x$ = TRIM$(x$) IF LEFT$(x$, 12) = "Directory of" THEN INCR numdir currentdir$ = MID$(x$, 14) IF filemode = 2 THEN 'dir mode INCR potfiles eodir$ = MID$(currentdir$, INSTR(-1, currentdir$, "\")+1) REGEXPR regex$ IN eodir$ TO posvar, lenvar IF posvar = 1 AND lenvar = LEN(eodir$) THEN 'full match INCR numfiles filelist$(numfiles) = currentdir$ END IF END IF ELSEIF LEN(x$) > 39 THEN IF filemode = 1 THEN INCR potfiles tim$ = MID$(x$, 19, 2) IF (tim$ = "AM" OR tim$ = "PM") AND MID$(x$, 25, 5) <> "