Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include files and folders with 7zip powershell

Im trying to make my powershell script zip up a few files and folders. At the moment I can make my script either zip all files (with no folders included), or zip all files with folders included but to the wrong path. An example would be if I have a folder named wordpress with files and a few subfolders. I need my zip file to be wordpress.zip, with all files and subfolders being in the root of that zip as opposed to \wordpress\files.*

Any help would be appreciated. Here is my code so far

function create-7zip([String] $aDirectory, [String] $aZipfile){
    [string]$pathToZipExe = "C:\Program Files\7-zip\7z.exe";
    [Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
    & $pathToZipExe $arguments;
}

create-7zip "$storageDir\wordpress\*.*"  "$storageDir\wordpress.zip"

The above example will only zip files inside of my target folder, I need it to include the subfolders as well.

like image 557
G3TH Avatar asked May 25 '12 18:05

G3TH


People also ask

How do I get a list of files in a directory and subfolders using PowerShell?

PowerShell utilizes the “Get-ChildItem” command for listing files of a directory. The “dir” in the Windows command prompt and “Get-ChildItem” in PowerShell perform the same function.

How do I add files to 7-Zip?

In the 7-Zip app, navigate to the folder with the ZIP file and the other files. Select the files, and click the Add button at the top. In the window that opens set the Archive format to ZIP, and in the Update mode, select 'Update and add files'. Click Ok, and the files will be added to the zipped file.


1 Answers

create-7zip "$storageDir\wordpress\*"  "$storageDir\wordpress.zip"

will include files and subfolders.

like image 185
jon Z Avatar answered Sep 25 '22 14:09

jon Z