Zip everything except one folder in directory

I am using PHP where I am trying to ZIP everything inside the folder except one folder called assets. I have tried this code below with a password for security :smile: but don’t know how I add the function which would be to ignore one folder called assets

    $dir = './../';
    $zip_file = "./backupfolder/";
    $rootPath = realpath($dir);
    $password = "123456";
    exec("zip -r -P {$password} {$zip_file} {$rootPath}");

//output: given all file in zip including assets
expect: ignore assets folder to zip

If there’s nothing in the zip documentation that tells you how to exclude a particular folder, why not do it in code? Use something like opendir() and readdir() to read through the path contents and just exclude whichever folders or files that you don’t want in the zip file.

ETA: a quick search for “zip exclude a folder” suggests that the -x parameter can be used to specify the folder that you want to exclude.

You may also want to exclude the folder called backupfolder. Backups of backups aren’t very useful.

I read this article here but when I run this code in cmd or PowerShell the error I am getting. even I downloaded the WinRAR software.
Please help how do I achieve the goal…

zip -r folder
'zip' is not recognized as an internal or external command,
operable program or batch file.

That error message suggests that zip is not installed on your computer.

I’ll move this to a more general section as this has no PHP content and you might get more useful responses there.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.