-1
我想壓縮一個飛蛾的文件夾到一個文件。例如201501適用於所有jan文件夾,我需要壓縮到一個名爲somename-2015-jan.zip的文件。所有其他的邏輯工作只zipplig部分顯示上述錯誤。我有PowerShell v3和,網絡4.54,當我可以調用System.IO.Compression.ZipFile] :: CreateFromDirectory來壓縮文件時出錯。帶有「4」參數的「CreateFromDirectory」:「路徑不是合法形式。」
$year = 2015
$base = "D:\Archive\"
$folder = Get-Content "D:\Archive\MasterFolder.txt"
#write-host $folder.count total lines read from file
foreach ($Fname in $folder)
{
$yearmonth = Get-Content "D:\Archive\duration.txt"
write-host $yearmonth.count total lines read from file
foreach ($date in $yearmonth)
{
$source = "$base$Fname\$date*"
#[string]$text = "$date"
$string = $date
#201501
$mmd = $string.Substring(4,2)
Write-host "fffcmd $mmd"
if ($mmd -gt 12) {
"$mmd is bigger than 12 Which is not valid,Please Correct The file name durations.txt and run the command again"
break
}
Else {
write-host " This is Source Folder Name !!!!!!!!!!!!!!!!!!!!$source"
switch($mmd)
{
"01" {$mm = "jan"
write-host "New mm is $mm"
}
"02" {$mm = "Feb"
write-host "New mm is $mm"
}
"03" {$mm = "Mar"
write-host "New mm is $mm"
}
"04" {$mm = "Apr"
write-host "New mm is $mm"
}
"05" {$mm = "May"
write-host "New mm is $mm"
}
"06" {$mm = "Jun"
write-host "New mm is $mm"
}
"07" {$mm = "Jul"
write-host "New mm is $mm"
}
"08" {$mm = "Aug"
write-host "New mm is $mm"
}
"09" {$mm = "Sep"
write-host "New mm is $mm"
}
"10" {$mm = "Oct"
write-host "New mm is $mm"
}
"11" {$mm = "Now"
write-host "New mm is $mm"
}
"12" {$mm = "Dec"
write-host "New mm is $mm"
}
default
{
Write-host "The Month Duration $mmd is not valid";continue
}
}
$destination = "$base$Fname\$Fname-$year-$mm.zip"
write-host " Destination $destination"
Add-Type -assembly "system.io.compression.filesystem"
function ZipFiles($zipfilename, $sourcedir)
{
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
$zipfilename, $compressionLevel, $false)
}
ZipFiles "$destination", "$source"
}
start-sleep -s 1
}
}