home *** CD-ROM | disk | FTP | other *** search
- { Wild card file copier for back-up of selected files from
- hard disk systems. Pauses as each floppy is filled to allow
- the next formatted floppy to be inserted. }
-
- { Command line entries are in the form: <copy mask> <dest drive> </c>
- where copy mask is <d:filename.typ> and wildcards are permitted;
- dest drive is <d:>; and
- /c is the optional confirm parameter (Y/N for each copy). }
-
- { Turbo 3.0 required. Thus DOS 2.0 or later is also required. }
-
- {This program accesses files using wild-cards. This method works with
- MS-DOS (or PC-DOS) versions 1 and later, though the program requires
- DOS 2.0 because of Turbo Pascal 3.0 . }
-
- {Copyright 1985 by David W. Carroll
- P.O Box 699
- Pine Grove, CA 95665 }
- {All commercial rights reserved.}
-
- { This program and over 600 more Turbo Pascal programs are
- available on the High Sierra RBBS-PC at 209-296-3534 }
-
- program copywc6;
-
- type
- regpack = record
- case integer of
- 1: (ax,bx,cx,dx,bp,si,di,ds,es,flags: integer);
- 2: (al,ah,bl,bh,cl,ch,dl,dh : byte)
- end;
-
- fcbarray = array[0..36] of char;
- strtype = string [14];
- comstr = string[127];
- datstr = string[2];
-
- const
- getdta = $1a;
- get1stdir = $11;
- getnextdir = $12;
- parsename = $29;
-
- var
- buffer : comstr;
- conf : string[10];
- inch : char;
- filestr,
- filename: strtype;
- indrive : string[2];
- outdrive : string[2];
- dfcb,
- dta,
- dta2 : fcbarray;
- disp : string[10];
- user_input,
- display,
- quit,
- confirm : boolean;
-
- function Uppercase(var Str : datstr) :datstr;
- var
- indx,len : Integer;
-
- begin
- Len := length(Str);
- for Indx := 1 to len do
- Str[Indx] := UpCase(Str[Indx]);
- uppercase := str
- end;
-
-
- function copyproc(fname:strtype) : byte;
- const
- recsize = 128;
- bufsize = 200;
-
- var
- source, dest : file;
- sourcename, destname : string[14];
- buffer : array[1..recsize,1..bufsize] of byte;
- recsread : integer;
- bufx, buff1: integer;
- docopy,
- writeerr : boolean;
- ch : char;
-
- begin
- if confirm then
- begin
- write('Copy ',indrive + fname,' ':(13-length(fname)),
- 'to ',outdrive,' (Y/N) ? ');
- repeat
- read(kbd,inch);
- until upcase(inch) in ['Y','N'];
- writeln(upcase(inch));
- docopy := upcase(inch) = 'Y';
- end
- else
- begin
- docopy := true;
- writeln('Copying ',indrive + fname,' ':(13-length(fname)),
- 'to ',outdrive);
- end;
- if docopy then
- repeat
- sourcename := indrive + fname;
- assign(source, sourcename);
- reset(source);
- destname := outdrive + fname;
- assign(dest,destname);
- rewrite(dest);
- writeerr := false;
- repeat
- blockread(source,buffer,bufsize,recsread);
- {$I-}
- blockwrite(dest,buffer,recsread);
- {$I+}
- writeerr := IOResult <> 0;
- until (recsread = 0) or writeerr;
- close(source);
- close(dest);
- if writeerr then
- begin
- erase(dest);
- writeln(^G'Insert next formatted diskette in B:');
- writeln('Then hit any key to continue copy.');
- read(kbd,ch);
- end;
- until not writeerr;
- copyproc := 0;
- end;
-
-
- procedure setDTA(num:byte); {set Disk Transfer Address}
- var
- regs: regpack;
-
- begin
- with regs do begin
- ah := getdta;
- case num of
- 1: begin
- ds := seg(dta);
- dx := ofs(dta);
- end;
- 2: begin
- ds := seg(dta2);
- dx := ofs(dta2);
- end;
- end;
- MSDOS(regs)
- end
- end; {setDTA}
-
- procedure calldir(calltype : byte; var errflag : byte);
- var
- regs: regpack;
-
- begin
- with regs do begin
- ah := calltype;
- cx := 0;
- ds := seg(dfcb);
- dx := ofs(dfcb);
- MSDOS(regs);
- errflag:= al
- end
- end; {calldir}
-
- procedure parse(var errflag:byte);
- var
- regs : regpack;
- begin
- with regs do begin
- ah := parsename;
- ds := seg(buffer[1]);
- si := ofs(buffer[1]);
- es := seg(dfcb);
- di := ofs(dfcb);
- al := $0F;
- MSDOS(regs);
- errflag := al;
- end;
- end; {parse}
-
- procedure find;
- const
- space = ' ';
- period = '.';
- var
- i,
- err: byte;
-
- begin
- for i := 0 to 36 do dfcb[i] := chr(0);
- { if not user_input then
- } writeln('Search mask: ',buffer:15);
- writeln;
- parse(err);
- setDTA(1); { set 1st DTA for get func.}
- calldir(get1stdir, err); { get first entry matching mask }
- if err > 0 then
- writeln('No files found');
- while err = 0 do
- begin
- filename:= '';
- for i:= 1 to 11 do
- begin
- if dta[i] <> space then
- filename := filename + dta[i];
- if i = 8 then filename := filename + period;
- end;
- { writeln(filename);}
- setDTA(2); { set 2nd DTA for file processing }
- err := copyproc(filename); { process file }
- if err = 0 then
- begin
- setDTA(1);
- calldir(getnextdir, err); { get next entry }
- end;
- end;
- writeln;
- end; {find}
-
- begin {copywc6}
- user_input := false;
- clrscr;
- writeln('Wild card file copy');
- writeln('by David W. Carroll');
- writeln;
- writeln('For transferring files from HD to floppies');
- writeln('Continues from last file as each floppy is filled');
- writeln;
- writeln('Command line arguments supported in the form:');
- writeln('A> copywc6 d:filename.typ d: /c ');
- writeln('where <d:filename.typ> is the copy mask with wildcards; ');
- writeln(' <d:> is the destination drive; and');
- writeln(' </c> is the optional "confirm each copy" flag.');
- writeln;
- writeln;
-
-
- if paramcount < 1 then
- begin
- write('Enter copy mask, <ENTER> to quit: ');
- readln(buffer);
- user_input := true;
-
- if length(buffer) > 0 then
- begin
- write('Confirm each file? (Y/N) ');
- repeat
- read(kbd,inch);
- until upcase(inch) in ['Y','N'];
- writeln(upcase(inch));
- confirm := upcase(inch) = 'Y';
-
- repeat
- write('Copy to drive: ');
- readln(outdrive);
- if (pos(':',outdrive)=0) and (length(outdrive)=1) then
- outdrive := outdrive + ':';
- until (length(outdrive)=2) and (upcase(outdrive[1]) in ['A'..'D']) and
- (outdrive[2] = ':');
- outdrive := uppercase(outdrive);
- end
- end;
-
-
- if paramcount > 0 then
- begin
- buffer := paramstr(1);
- if pos(':',copy(buffer,1,2)) > 0 then
- indrive := copy(buffer,1,2)
- else
- indrive := '';
- indrive := uppercase(indrive);
-
- if paramcount > 1 then
- begin
- outdrive := paramstr(2);
- if (pos(':',outdrive)=0) and (length(outdrive)=1) then
- outdrive := outdrive + ':';
- if not ( (length(outdrive)=2) and (upcase(outdrive[1]) in ['A'..'D']) and
- (outdrive[2] = ':')) then
- repeat
- write('Copy to drive: ');
- readln(outdrive);
- if (pos(':',outdrive)=0) and (length(outdrive)=1) then
- outdrive := outdrive + ':';
- until (length(outdrive)=2) and (upcase(outdrive[1]) in ['A'..'D']) and
- (outdrive[2] = ':');
- end
- else
- begin
- repeat
- write('Copy to drive: ');
- readln(outdrive);
- if (pos(':',outdrive)=0) and (length(outdrive)=1) then
- outdrive := outdrive + ':';
- until (length(outdrive)=2) and (upcase(outdrive[1]) in ['A'..'D']) and
- (outdrive[2] = ':');
- end;
- outdrive := uppercase(outdrive);
-
- confirm := false;
- if paramcount > 2 then
- begin
- conf := paramstr(3);
- if (conf[1] = '/') and (upcase(conf[2]) = 'C') then
- confirm := true
- else
- begin
- write('Confirm each file? (Y/N) ');
- repeat
- read(kbd,inch);
- until upcase(inch) in ['Y','N'];
- writeln(upcase(inch));
- confirm := upcase(inch) = 'Y';
-
- end
- end
- else
- begin
- write('Confirm each file? (Y/N) ');
- repeat
- read(kbd,inch);
- until upcase(inch) in ['Y','N'];
- writeln(upcase(inch));
- confirm := upcase(inch) = 'Y';
- end;
-
- find;
-
- repeat
- quit := false;
- buffer := '';
- write('Enter next copy mask, <ENTER> to quit: ');
- readln(buffer);
- if pos(':',buffer)>0 then
- indrive := copy(buffer,1,2)
- else
- indrive := '';
- indrive := uppercase(indrive);
- if length(buffer) > 0 then
- begin
-
- write('Confirm each file? (Y/N) ');
- repeat
- read(kbd,inch);
- until upcase(inch) in ['Y','N'];
- writeln(upcase(inch));
- confirm := upcase(inch) = 'Y';
-
- find;
-
- end
- else
- begin
- write('Quit? (Y/N) ');
- repeat
- read(kbd,inch);
- until upcase(inch) in ['Y','N'];
- writeln(upcase(inch));
- quit := upcase(inch) = 'Y';
- end
- until quit;
- end
- else
- writeln('Program Terminated');
- end. {copywc6}
-