使用PowerShell压缩文件夹

Vivaldi数据迁移过程中,压缩用户数据文件夹如下。

# Vivaldi User Data Folder
$toArchive = Join-Path -Path $env:UserProfile -ChildPath "AppData\Local\Vivaldi\User Data\"

# where to store the zip file
$zipFileName = -join((Get-Date -Format "yyyyMMdd_"), 'userData.zip')
$destFolder = "D:\Backup\"
$filePath = Join-Path -Path $destFolder -ChildPath $zipFileName

 If(Test-path -Path $destFolder) {
    # OK
    if ( Test-Path -Path $filePath ){
        # alreay existed
        exit
    }else{
        Out-Host -InputObject " Archiving $toArchive"
        Out-Host -InputObject " to $filePath"
        $info = Compress-Archive -DestinationPath $filePath -Path $toArchive -CompressionLevel Optimal
        Out-Host -InputObject $info
    }
 }else{
    # disk is umounted or busy
    exit
 }

你可能感兴趣的:(使用PowerShell压缩文件夹)