PEAR Manual
Prev |  | Next

# Archive_Tar::createModify()

Archive_Tar::createModify() -- create a new archive

## Synopsis

    require_once 'Archive/Tar.php';

``boolean createModify` (array $filelist, string $add_dir [, string $remove_dir = ''])`

## Description

This method creates the archive file and adds the listed files or directories.

If the file already exists and is writable, it is replaced by the new tar. It is a 'create' and not a 'add'. If the file exists and is read-only or is a directory, it is not replaced.

## Parameter

- `mixed $filelist` - an array of filenames and directory names, or a single string with names separated by a single blank space.

- `string $add_dir` - contains a path to be added to the memorized path of each element in the list.

- `string $remove_dir` - contains a path to be removed from the memorized path of each element in the list, when relevant. Default is an empty string.

## Return value

`boolean` - Returns `TRUE` on success, `FALSE` on failure.

## Throws

Table 38-1. Possible PEAR_Error values

Error code | Error message | Reason | Solution
--- | --- | --- | ---
`NULL` | "Invalid file list" | The argument for the function is not correctly formatted or build. | Check for typing mistakes in the argument

## Note

This function can not be called statically.

## Example

Example 38-1. Create a new compressed archive in a new directory
    $tar_object = new Archive_Tar("tarname.tgz", true);
    $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
    $v_list[0]="dev/file.txt";
    $v_list[1]="dev/data/";
    $v_list[2]="log/file.log";
    $tar_object->createModify($v_list, "install", "dev");
    // files are stored in the archive as :
    //   install/file.txt
    //   install/data
    //   install/data/file1.txt
    //   install/data/... all the files and sub-dirs of data/
    //   install/log/file.log

Example 38-2. Create a new compressed archive in a new directory (especially for Windows)
    $tar_object = new Archive_Tar("tarname.tgz", true);
    $tar_object->setErrorHandling(PEAR_ERROR_PRINT);
    $v_list[0]="c:\\dev\\file.txt";
    $v_list[1]="c:\\dev\\data\\";
    $v_list[2]="c:\\log\\file.log";
    $tar_object->createModify($v_list, "install/temp", "c:\\dev");
    // files are stored in the archive as :
    //   install/temp/file.txt
    //   install/temp/data
    //   install/temp/data/file1.txt
    //   install/temp/data/... all the files and sub-dirs of data/
    //   install/temp/log/file.log

Prev | Home | Next
Archive_Tar::create() | Up | Archive_Tar::extract()