Forum Discussion
Sixdog
Aug 08, 2023Copper Contributor
Macos compress can't zip a folder.but can zip a file
$compress = @{
Path = "./20230801"
CompressionLevel = "Fastest"
DestinationPath = "./Draft.zip"
}
Compress-Archive @compress
- Aug 09, 2023
This is a normal "file not found" error, meaning it cannot see the directory you specified.
Be careful when using file paths in .NET as relative paths are not always supported and even when they are, do not always yield expected results.
Try something like this instead (to use the full path to the directory):
[System.IO.Compression.ZipFile]::CreateFromDirectory( (Get-Item -Path ".\NewFolder").FullName , (Join-Path -Path ((Get-Item -Path .).FullName) -ChildPath "forum.zip") , [System.IO.Compression.CompressionLevel]::Fastest , $true );Cheers,
Lain
Sixdog
Aug 09, 2023Copper Contributor
thank u help very much, but i tried it,it doesn't work,this is the exception
PS /Users/sixdog/Documents/PowerShell> [System.IO.Compression.ZipFile]::CreateFromDirectory("./20230701/", "./dddd.zip", [System.IO.Compression.CompressionLevel]::Fastest, $true);
MethodInvocationException: Exception calling "CreateFromDirectory" with "4" argument(s): "Unable to find the specified file."
PS /Users/sixdog/Documents/PowerShell>
PS /Users/sixdog/Documents/PowerShell> [System.IO.Compression.ZipFile]::CreateFromDirectory("./20230701/", "./dddd.zip", [System.IO.Compression.CompressionLevel]::Fastest, $true);
MethodInvocationException: Exception calling "CreateFromDirectory" with "4" argument(s): "Unable to find the specified file."
PS /Users/sixdog/Documents/PowerShell>
LainRobertson
Aug 09, 2023Silver Contributor
This is a normal "file not found" error, meaning it cannot see the directory you specified.
Be careful when using file paths in .NET as relative paths are not always supported and even when they are, do not always yield expected results.
Try something like this instead (to use the full path to the directory):
[System.IO.Compression.ZipFile]::CreateFromDirectory(
(Get-Item -Path ".\NewFolder").FullName
, (Join-Path -Path ((Get-Item -Path .).FullName) -ChildPath "forum.zip")
, [System.IO.Compression.CompressionLevel]::Fastest
, $true
);
Cheers,
Lain
- SixdogAug 09, 2023Copper Contributorthank you very much,from your response i studied the powershell's knowledge.