; TOSHORT
;
; Program for Proteus
;
; (C) 2001-2004 Simone Zanella Productions
;
; This program renames to Dos format (8 + 3 characters) all files corresponding to filespec.
#!proteus -z
IF ISEMPTY(ARGV(5))
CONSOLELN "Syntax: TOSHORT filespec"
CONSOLELN ""
CONSOLELN "Purpose: renames to Dos format (8 + 3 characters) all files corresponding to filespec"
ABORT 0
FI
Path = SplitPath(ARGV(5))
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)
AVLTRAVERSE(A, RenameFile)
ABORT 0
FUNCTION FindExt(name)
P = STRRSTR(name, ".")
IF NEQ(P, 0)
RETURN LEFT(UPPER(STRTRAN(RESTFROM(name, P), " ", "")), 4)
FI
RETURN ""
FUNCTION RenameFile(name, trash)
lfnsource = _Path name
ext = FindExt(name)
name = LEFT(STRTRAN(name, " ", ""), 8)
dossource = _Path name ext
pos = 1
WHILE ISFILE(dossource)
IF LT(STRLEN(name), 8)
name = name "1"
pos = 1
ELSE
Z = LEFT(RIGHT(name, pos), 1)
IF LT(ASC(Z), ASC("Z"))
N = INC(ASC(Z))
IF LE(N, ASC("0"))
N = ASC("1")
ELSE
IF AND(GT(N, ASC("9")), LT(N, ASC("A")))
N = ASC("A")
FI
FI
Z = CHR(N)
ELSE
INC(@pos)
CONTINUE
FI
name = LEFT(name, SUB(STRLEN(name), pos)) Z RIGHT(name, DEC(pos))
FI
dossource = _Path name ext
LOOP
CONSOLELN dossource
FRENAME(lfnsource, dossource)
RETURN 0
FUNCTION SplitPath(pathname)
P = STRRSTR(pathname, "\\")
IF NEQ(P, 0)
RETURN LEFT(pathname, P)
FI
RETURN ""