; TOLOWER
;
; Program for Proteus
;
; (C) 2001-2004 Simone Zanella Productions
;
; This program renames all files corresponding to filespec so that their names are all lowercase.
#!proteus -z
IF ISEMPTY(ARGV(5))
CONSOLELN "Syntax: TOLOWER filespec"
CONSOLELN ""
CONSOLELN "Purpose: convert all filenames to lower case."
ABORT 0
FI
; Split path from file name
Path = SplitPath(ARGV(5))
; Find files corresponding to filespec and store their names into an AVL
; (info associated with each name is "." and is ignored in the rest of the program)
H = DIROPEN(ARGV(5), 1)
F = IIF(NEQ(H, -1), 1, 0)
A = AVLNEW()
WHILE GT(F, 0)
AVLSET(A, DIRLAST(H, 1), ".")
F = DIRNEXT(H)
LOOP
DIRCLOSE(H)
; Travers AVL tree, renaming files to lower case
AVLTRAVERSE(A, RenameFile)
ABORT 0
FUNCTION RenameFile(name, trash)
dossource = LOWER(SHORTNAME(_Path name))
lfnsource = _Path name
FRENAME(lfnsource, dossource)
RETURN 0
FUNCTION SplitPath(pathname)
P = STRRSTR(pathname, "\\")
IF NEQ(P, 0)
RETURN LEFT(pathname, P)
FI
RETURN ""