Tree folder/sub-folder/files archive issues...

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
shiroscout
Posts: 41
Last visit: Sat Jul 15, 2023 7:13 pm

Tree folder/sub-folder/files archive issues...

Post by shiroscout »

Product: PowerShell Studio 2019 (64 Bit)
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 :
Get-ChildItem $listBox.Items -Recurse | Compress-Archive -CompressionLevel Optimal -DestinationPath "c:\Temp\Adircopy"
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.

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"
Attachments
Capture3.PNG
Capture3.PNG (57.05 KiB) Viewed 942 times
Capture2.PNG
Capture2.PNG (82.86 KiB) Viewed 942 times
Capture1.PNG
Capture1.PNG (67.93 KiB) Viewed 942 times
Thank You,

Wayne
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tree folder/sub-folder/files archive issues...

Post by jvierra »

Pick one thing that doesn't work and let's try to understand what you are seeing. Just saying it doesn't work doesn't provide any useful information.

To scatter-add to an archive I suggest adding the files to an array then piping the array to "Compress-Archive".
This topic is 1 year and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked