Im producing some automated tasks at work where i need to zip certain files and/or folders. What im trying to do is getting zip the text files in folder 1 which contains 4 txt files.
Executing this command gives an error but still zips the txt files :
Exception calling "CreateFromDirectory" with "4" argument(s): "The directory name is invalid.
"
At line:15 char:13
+ [System.IO.Compression.ZipFile]::CreateFromDirectory($Source, "$Sour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
What i got now is:
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
$includeBaseDirectory = $false
$compressionLevel= [System.IO.Compression.CompressionLevel]::Optimal
$source = "C:\folder1\*"
Get-ChildItem $source -include *.txt |
Foreach {
$Source = $_.fullName
[System.IO.Compression.ZipFile]::CreateFromDirectory ($Source, "$Source.zip",$compressionLevel, $includebasedirectory)
}
Also if i want to zip the folders inside folder1 i use -directory switch instead of include. that doesnt produce any error messages. any suggestions?