简体   繁体   中英

Deleting folder within a folder after zipping and deleting some files

This is follow-up question after on my question .

Folder
  subfolders
  imagefolder
  important.txt
  index.txt

I have a subfolder, How to zip the Folder , then delete all files including all the folders within the Folder exempt the important.txt ?

From the previous post . I've got this:

$zipFile = "./testZip.zip";
$zipArchive = new ZipArchive();

if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE))
    die("Failed to create archive\n");

$zipArchive->addGlob("./*.txt");
if (!$zipArchive->status == ZIPARCHIVE::ER_OK)
    echo "Failed to write files to zip\n";

$zipArchive->close(); 

But it gave me this output: testZip.zip has been created but including only file: important.txt then the subfolders is not deleted.

If you use the solution I posted in your other question and replace the exec('rm...') call with

exec('find Folder -mindepth 1|grep -v important.txt|xargs rm -r');

then it will delete all files except important.txt in 'Folder'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM