Uses Dos;
Var
  ConfigFile,BBSfile,HdrFile : text;
  files : SearchRec;
  temp,RealName : string;
  LenOfSpace : byte;
  path1 : string;
  spaces : string;
  i : byte;
  err : integer;

Procedure MakeFiles(path : string);
Begin
  FindFirst(path+'*.Hdr',AnyFile,files);
  err := doserror;
  if err = 0 then
   begin
    Assign(BBSFile,path+'files.bbs')
    {$I-};
    Append(BBSFile);
    If IOResult <> 0 then Rewrite(BBSFile);
    {$I+}
    while DOSError = 0 do
      begin
        Assign(HDRfile,path+files.name);
        Reset(HDRFile);
        for i := 1 to 4 do readln(HDRFILE,temp);
        ReadLn(HDRFile,RealName);
        delete(temp,1,8);
        delete(RealName,1,8);
        close(HdrFile);
        erase(HdrFile);
        LenOfSpace := Pos(' ',RealName);
        Delete(RealName,LenOfSpace,Length(RealName)-LenOfSpace+1);
        spaces := '';
        for i := 1 to 13-length(files.name) do spaces := spaces + ' ';
        WriteLn(BBSFile,RealName,spaces,'[00] ',temp);
        FindNext(files)
      end;
      close(BBSFile);
      WriteLn('Files.bbs заполнено содержанием HDR файлов','  ',path);
    end
  else case err of
   2: writeln('File not found','  ',path);
   3: WriteLN('Path not found','  ',path);
   5: WriteLN('Access denied','  ',path);
   6: WriteLN('Invalid handle','  ',path);
   8: WriteLN('Not enough memory','  ',path);
  10: WriteLN('Invalid environment','  ',path);
  11: WriteLN('Invalid format','  ',path);
  18: WriteLN('No more files','  ',path)
  end

End;

Begin
  path1 := ParamStr(0);
  FindFirst('hdr2bbs.cfg',AnyFile,files);
  if DosError = 0 then
    begin
      Assign(configfile,files.name);
      Reset(configfile);
      repeat
        ReadLn(configfile,path1);
        makefiles(path1);
      until EOF(configfile);
      close(configfile)
    end;
End.