; TOUPPER
;
; Program for Proteus
;
; (C) 2001-2004 Simone Zanella Productions
;
; This program renames to uppercase all files corresponding to filespec.
#!proteus -z
IF ISEMPTY(ARGV(5))
CONSOLELN "Syntax: TOUPPER filespec"
CONSOLELN ""
CONSOLELN "Purpose: convert all filenames to upper case."
ABORT 0
FI
; Split path from file name
Path = SplitPath(ARGV(5))
; Find files corresponding to filespec and store them 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 upper case
AVLTRAVERSE(A, FileRename)
ABORT 0
FUNCTION FileRename(name, trash)
dossource = UPPER(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 ""