0

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.

Community
  • 1
  • 1
woninana
  • 3,409
  • 9
  • 42
  • 66
  • Did you try my approach? You would also have to add a shell('rm -r Folder/subfolders'); to delete the subfolders. Its a very naive approach but also very robust as long as you do not change the folders content. – Kevin Read Feb 06 '11 at 18:48
  • that is the problem, i can't use your method since the content of the folders are changing. It's not consistent files..except on the important.txt – woninana Feb 06 '11 at 18:51
  • I added an answer that doesn't have this problem. – Kevin Read Feb 06 '11 at 22:01
  • I appreciate your answer, but Its not the answer for my problem.I have less than 2 hours in answering this. This is for my school project. I will fail if i don't get this solve. – woninana Feb 06 '11 at 22:42

1 Answers1

0

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'.

Kevin Read
  • 2,173
  • 16
  • 23