使用PowerShell压缩文件夹

2017-08-30  本文已影响0人  喷射的熔浆

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
 }
上一篇下一篇

猜你喜欢

热点阅读