This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0048.pas
More file actions
114 lines (95 loc) · 2.74 KB
/
Copy path0048.pas
File metadata and controls
114 lines (95 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{$S-,V-,R-,F+}
PROGRAM REX;
{ Rename all files matching one extension with another
CAUTION !!! This program will rename FILES !!!!!!!!
Takes to parameters : Ext1(current) and Ext2(whatever)
i.e. *.XXX to *.PAS or *.MOD to *.INT
Uses some of the routines from EDDY THILLEMAN'S recursive directory roam
whice can be found in the SWAG distribution
Gayle Davis 1/26/94 }
USES DOS, CRT;
TYPE
ProcessType = PROCEDURE (Path : PathStr; FR : SearchRec);
CONST
NotGoodFile : WORD = Directory + Hidden + Readonly + VolumeID + Sysfile;
VAR
Ext1 : Pathstr;
Ext2 : Pathstr;
ExitSave : POINTER;
PROCEDURE Frename (SourceFile, TargetFile : STRING; VAR ErrCode : BYTE);
VAR
reg : REGISTERS;
BEGIN { Frename }
SourceFile := CONCAT (SourceFile, #0);
TargetFile := CONCAT (TargetFile, #0);
reg.ds := SEG (SourceFile [1]); reg.dx := OFS (SourceFile [1]);
reg.es := SEG (TargetFile [1]); reg.di := OFS (TargetFile [1]);
reg.ah := $56;
MSDOS (reg);
ErrCode := 0;
IF (reg.flags AND FCarry) = 1 THEN ErrCode := reg.ax;
END; { Frename }
PROCEDURE DoitHere (Path : PathStr; FR : SearchRec); FAR;
VAR
Name1,
Name2 : PathStr;
D : PathStr;
N : NameStr;
E : ExtStr;
Err : BYTE;
BEGIN
IF (FR.Attr AND NotGoodFile) <> 0 THEN EXIT;
FSplit(FR.Name, D, N, E);
Name1 := Path + FR.Name;
Name2 := Path + N + Ext2;
WRITELN (Name1, ' ', Name2);
FRename(Name1,Name2,Err);
END;
FUNCTION Wildcard (Name : PathStr) : BOOLEAN ;
BEGIN
Wildcard := (POS ('*', Name) <> 0) OR (POS ('?', Name) <> 0) AND (POS('.',Name) > 0);
END ;
Procedure PathAnalyze (P: PathStr; Var D: DirStr; Var Name: NameStr);
Var
N: NameStr;
E: ExtStr;
begin
FSplit(P, D, N, E);
Name := N + E;
end;
PROCEDURE FindFiles (fMask : PathStr; fAttr : WORD; Process : ProcessType);
VAR
FR : SearchRec;
Path : PathStr;
Mask : NameStr;
BEGIN
PathAnalyze(fMask,Path,Mask);
FINDFIRST (FMask, FAttr, FR);
WHILE DosError = 0 DO
BEGIN
Process (Path,FR);
FINDNEXT (FR);
END;
END;
PROCEDURE ExitHandler; FAR;
{ Return the cursor to its original shape }
BEGIN
ExitProc := ExitSave
END;
BEGIN
ExitSave := ExitProc;
ExitProc := @ExitHandler;
ClrScr;
IF PARAMCOUNT < 2 THEN
BEGIN
WriteLn('REX : Rename all files matching Ext1 to Ext2');
WRITELN('Needs 2 Parameters .. *.ext1 *.ext2');
HALT;
END;
Ext1 := ParamStr(1);
Ext2 := ParamStr(2);
IF NOT WildCard(Ext1) THEN HALT; { must contain a wildcard }
IF NOT WildCard(Ext2) THEN HALT;
Ext2 := COPY(Ext2,POS('.',Ext2),$FF); { only want the extension }
FindFiles (Ext1, Anyfile, DoitHere);
END.