Build: v5.6.164
OS: Windows 10 Pro (64 Bit)
Build: v10.0.19045.0
Hello,
I am new just so you can brace yoursself.
I have predesigned form I am modifying code.
It's a learning, training project for myself.
I'm sure there of lots of cleanup and design issues, but I am concerned with a specific peice of code.
I have tried compress-archive, 7zip, compact, and in all cases, if I can sortof get the syntax correct, it will archive the files, and even copy over folvder, but the directory structure is all over the place with sub/sub-sub folder in root folder of archive, etc...
What the form is supposed to do is let me point it to my project folder, then add the project folder, or even limited project folders, search and exclude certain files, and zip up to archive, with full folder structure in-tact. If shown, I can use another mehod or way to do this, as I might be using the wrong commands to accomplish this.
It does not work if I only use line of code like this :
and I have tried, as mentioned, 2-3 different archive programs, and basically get the same results when I get it to actually work and archive files to completion.Get-ChildItem $listBox.Items -Recurse | Compress-Archive -CompressionLevel Optimal -DestinationPath "c:\Temp\Adircopy"
Code: Select all
$buttonCompressToSingleArch_Click={
$buttonCompressToSingleArch.Text = "Add All"
foreach ($item in $listBox.Items)
{
$i = Get-Item -LiteralPath $item
if ($i -is [System.IO.DirectoryInfo])
{
write-host ("`t" + $i.Name + " [Directory]")
}
else
{
write-host ("`t" + $i.Name + " [" + [math]::round($i.Length/1MB, 2) + " MB]")
}
}
Get-ChildItem $listBox.Items -Recurse -Exclude *.pfx, *.msi, *.exe, *.psf,*.psproj, *.psd1, *.psm1 |
Where-Object { $_.Directory -notmatch 'folder1|folder2|folder3' } |
Compress-Archive -CompressionLevel Optimal -DestinationPath "c:\Temp\Adircopy"