home *** CD-ROM | disk | FTP | other *** search
- program nmove;
-
- type
- anystr = string[255];
- parmtype = string[127];
- pathtype = string[62];
- drivetype = string[2];
- rtype = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags:integer
- end;
-
- var
- fname,dirname,nname,rname : anystr;
- command : parmtype;
-
- procedure rename(x,y:pathtype);
-
- var
- wx,wy : pathtype;
- reg : rtype;
-
- function currentdrive: drivetype;
- var
- w : drivetype;
- reg : rtype;
-
- begin
- reg.ax:=$1900;
- intr($21,reg);
- w:='A:';
- w[1]:=chr(ord(w[1])+lo(reg.ax));
- currentdrive:=w
- end;
-
- begin
- wx := x + chr(0);
- wy := y + chr(0);
- if wx[2]<>':' then wx :=currentdrive+wx;
- reg.ax := $5600;
- reg.ds := seg(wx[1]);
- reg.dx := ofs(wx[1]);
- reg.es := seg(wy[1]);
- reg.di := ofs(wy[1]);
- intr($21,reg);
- if (reg.flags and 1) <> 0 then
- begin
- WRITELN;
- writeln;
- writeln('Error -- invalid rename request.');
- writeln(' -- from: ''',x,'''');
- writeln(' -- to: ''',y,'''');
- halt
- end
- end;
-
- (*--------------------------------------------------------------------------*)
- (* GETPARMS.INC *)
- (* Turbo Pascal procedure to retrieve command line parameters. *)
- (* Copywrite 1984 Michael A. Covington *)
- (*--------------------------------------------------------------------------*)
-
- procedure getparm(var s:parmtype);
- (*--------------------------------------------------------------------------*)
- (* returns first available parameter from DOS command line and removes it *)
- (* next parameter will be returned on next call. If no more parameters *)
- (* are available, returns a null string. *)
- (*--------------------------------------------------------------------------*)
- var
- parms : parmtype absolute CSEG:$80;
-
- begin
- s:='';
- (* parms[1] exists even when length is zero *)
- while ( length(parms) > 0) and (parms[1] = ' ') do
- delete(parms,1,1);
- while (length(parms) > 0) and (parms[1] <> ' ') do
- begin
- s:=s+parms[1]; delete(parms,1,1)
- end
- end;
-
- begin {main}
-
- getparm(command);
- fname := (command);
- getparm(command);
- rname := (command);
-
- if length(fname) = 0 then
- begin
- writeln;
- write('file to move: ');
- readln(fname);
- write('new directory: ');
- readln(dirname);
- if dirname = '\' then dirname := ''
- else dirname := dirname;
- write('name of moved file (<cr> for same name): ');
- read(nname);
- if length(nname) = 0 then rname := (dirname+'\'+fname)
- else
- rname := (dirname+'\'+nname);
- rename(fname,rname);
- end
- else
- if (fname) = '?' then
- begin
- writeln;
- WRITELN('A move can be executed from the command line, bypassing prompts,');
- WRITELN('by entering:');
- WRITELN;
- WRITELN('Syntax: Nmove <fname> <\path\fname2>');
- WRITELN;
- WRITELN(' Where <fname> is the file to move, <\path> ');
- WRITELN(' is the destination directory, and <fname2> ');
- WRITELN(' is the destination filename. ');
- WRITELN;
- WRITELN(' Note: the destination <fname2> may be ');
- WRITELN(' different from the source <fname>. ');
- WRITELN('');
- WRITELN('Nmove will not write over an existing file ');
- WRITELN('in the destination directory.');
- delay(1000);
- end
- else
- rename(fname,rname);
- end.