简体   繁体   English

Powershell语法,使用zip压缩和全局变量?

[英]Powershell syntax , using zip compression and global variables?

I was playing around with the system zip compression, before we always used 7zip and I want to be more agile with all our scripts. 在我们总是使用7zip之前,我正在玩系统zip压缩,我希望对所有脚本更敏捷。

I found this : 我找到了这个 :

$sourceFolder = "C:\folder1"
$destinationZip = "c:\zipped.zip" 
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder, $destinationZip)

this works fine! 这很好用! But, 但,

as soon as i create a function out of this and put in global variables i am not able to run the script. 一旦我创建了一个函数并放入全局变量,我就无法运行该脚本。

$dest = "C:\_archive\ImportJournals\ImportJournals.zip"

$source = "C:\_archive\ImportJournals\temp\"



function ZipFiles ([string]$destination, [string]$sourcedir )
{
    [Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
    [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $destination) 
}

ZipFiles ( $dest, $source )

I get an Error : "The path if not of an legal form." 我得到一个Error : "The path if not of an legal form."

Any Ideas? 有任何想法吗?

调用Powershell函数的语法是:

ZipFiles $dest  $source 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM