#COMPILE EXE #DIM ALL %MAXDIRSIZE = 16384 %VERBOSE = 1 FUNCTION PBMAIN () AS LONG LOCAL x$ PRINT "NoUnder" PRINT "Converts all underscores to spaces in this directory and its subdirs." PRINT PRINT "Beginning in " & CURDIR$ PRINT "OK? (y/N)" x$ = WAITKEY$ IF LCASE$(x$) = "y" THEN STDOUT "Made " & FORMAT$(DoDirectory(CURDIR$), "0,") & " changes" ELSE PRINT "Aborted" END IF PRINT "Bye" END FUNCTION FUNCTION DoDirectory(startDir$) AS LONG LOCAL numentries&, temp$, ctr&, res& 'Move to appropriate directory IF %VERBOSE THEN STDOUT "Scanning directory """ & startDir$ & """ "; CHDIR startDir$ 'Scan the current directory DIM Listing(%MAXDIRSIZE) AS DIRDATA temp$ = DIR$("*.*", %NORMAL OR %SUBDIR TO Listing(numentries&)) WHILE LEN(temp$) AND numentries& < %MAXDIRSIZE INCR numentries& temp$ = DIR$(NEXT, TO Listing(numentries&)) WEND IF %VERBOSE THEN STDOUT " [" & FORMAT$(numentries&, "0,") & " entries]" 'Clean up files and directories FOR ctr& = 1 TO numentries& IF Listing(ctr&).FileAttributes AND %NORMAL = %NORMAL OR Listing(ctr&).FileAttributes = %SUBDIR THEN 'This will skip hidden and system files temp$ = TRIM$(Listing(ctr&).FileName) IF INSTR(temp$, "_") > 0 THEN 'Needs a rename REPLACE "_" WITH " " IN temp$ 'Eliminate underscores WHILE INSTR(temp$, " ") REPLACE " " WITH " " IN temp$ 'Eliminate double spaces WEND INCR res& IF Listing(ctr&).FileAttributes <> %SUBDIR THEN 'Regular file NAME TRIM$(Listing(ctr&).FileName) AS temp$ 'Do rename IF %VERBOSE THEN STDOUT " Fixed filename """ & temp$ & """" ELSE 'Directory NAME TRIM$(Listing(ctr&).FileName) AS temp$ 'Do rename Listing(ctr&).Filename = temp$ 'Update entry (if we have a collision this will cause an error...***TODO) IF %VERBOSE THEN STDOUT " Fixed dirname """ & temp$ & """" END IF END IF END IF NEXT 'Recurse FOR ctr& = 1 TO numentries& IF Listing(ctr&).FileAttributes = %SUBDIR THEN res& = res& + DoDirectory(startDir$ & "\" & TRIM$(Listing(ctr&).Filename)) END IF NEXT FUNCTION = res& END FUNCTION