Forum Discussion

Sixdog's avatar
Sixdog
Copper Contributor
Aug 08, 2023
Solved

Macos compress can't zip a folder.but can zip a file

    $compress = @{ Path = "./20230801" CompressionLevel = "Fastest" DestinationPath = "./Draft.zip" } Compress-Archive @compress    
  • LainRobertson's avatar
    LainRobertson
    Aug 09, 2023

    Sixdog 

     

    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

Resources