 program rename;   {rename files or directories}

    type
       regset = 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;

    var
       params : regset;
       fcb : array[-7..37] of byte;   {Extended FCB}
       file_name : string[20];
       i : integer;

    begin
       fcb[-7] := $FF;   {setup Extended FCB}
       fcb[-1] := $16;   {match on anything}
       with params do begin
          write('Old File Name: ');
          readln(file_name);
          file_name := file_name + ' ';   {terminate to stop parse}
          ax := $2901;   {parse the filename}
          ds := seg(file_name[1]);
          si := ofs(file_name[1]);
          es := seg(fcb[0]);
          di := ofs(fcb[0]);
          msdos(params);
          if al <> 0 then begin
             writeln(^G'invalid file name');
             halt;
             end;

          write('New File Name: ');
          readln(file_name);
          file_name := file_name + ' ';
          ax := $2903;   {parse the file name}
          ds := seg(file_name[1]);
          si := ofs(file_name[1]);
          es := seg(fcb[$10]);
          di := ofs(fcb[$10]);
          msdos(params);
          if al <> 0 then begin
             writeln(^G'invalid file name');
             halt;
             end;

          ah := $17;   {rename call}
          ds := seg(fcb[-7]);   {use the Extended FCB}
          dx := ofs(fcb[-7]);
          msdos(params);
          if al <> 0 then writeln(^G'Rename Unsuccessful!!')
          else writeln('Done');
          end;
       end.
