[fpc-pascal] Adding files to a tar file

Flávio Etrusco flavio.etrusco at gmail.com
Wed Jan 22 02:09:23 CET 2014


On Tue, Jan 21, 2014 at 10:45 PM, luciano de souza <luchyanus at gmail.com> wrote:
> Hello all,
>
> This code should add all the files of a directory in a tar file.
>
> program e01;
> {$mode objfpc}{$H+}
>
> uses
> libtar, sysutils;
>
> var
> archive: TTarWriter;
> search: TSearchRec;
>
> BEGIN
> archive := TTarWriter.create('arquivo.tar');
> with archive do
> begin
> try
> FindFirst('/home/luciano/Documentos/*', faAnyFile, search);
> repeat
> if (search.name <> '.') and (search.name <> '..') then
> AddFile(search.name);
> until FindNext(Search) = 0;
> finally
> free;
> end;
> end;
> END.
>
> The program compiles, but I got an error. The message says that the
> first file of the directory can't be opened.
>
> What is wrong?

Probably because Search.Name contains only the filename, but AddFile
expects an absolute path (or relative to GetCurrentDir)?


> My second doubt is: I am running this program in Ubuntu 13.10. If I
> run it in Windows, will a external library be necessary or all the
> code is included in lib tar unit?
>
> Regards,

AFAICS all the code is included in the libtar unit.

-Flávio



More information about the fpc-pascal mailing list