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.
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.
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.
create-7zip "$storageDir\wordpress\*" "$storageDir\wordpress.zip"
will include files and subfolders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With