Powershell, temp folder while zipping

Jan 28, 2011 at 2:26 PM
Edited Jan 28, 2011 at 2:47 PM

During the zip process, a temporary file is created.  Can I set the property of where this temporary file should exist during the zipping process?  I don't have enough space for it on the source or target drives.


Here is the powershell function I use to zip up.


function global:dotnetzip
    #using  dotnetzip "c:\SourceFolder" "c:\destination.zip" "FolderNameInsideRootOfZip"
    # http://dotnetzip.codeplex.com/Wiki/View.aspx?title=PS-Examples
    $source = $args[0]
    $destinationinput = $args[1]
    $FolderName = $args[2]
    "Will zip $source to $destinationinput under $FolderName" | Out-File $logfilename -Append
    $destinationobject = $null

    $destinationobject = new-object Ionic.Zip.ZipFile
    $Zip64 = new-object Ionic.Zip.Zip64Option
    $Zip64.value__ = $true
    $destinationobject.UseZip64WhenSaving = $Zip64
    $destinationobject.AddDirectory($source, $FolderName)

To call the function, I do:

dotnetzip "$vhdpath" "$zipfilename" "$vhdzipname"


Now, (just as an fyi) with this small test script, I can find a drive on the server that has the most space and check for a minimum amount:

$freedrive = $null
$drivelist = Get-PSDrive -PSProvider filesystem

[array]$drivearray = $drivelist | Sort-Object Free -Descending | Where-Object {$_.Free -ne $null}
if ($drivearray[0].free -ge "5000000000"){ # 5 gigs or more
    $freedrive = $drivearray[0].root

$templocation = ($freedrive + "test.txt")

#creates file to verify process worked
New-Item $templocation -type file


I have checkout out my $destinationobject object with get-member to see if there is anything there to set the location of the temporary file, along with other objects.  I cannot see anything there to do this.

When I call the $destinationobject.AddDirectory($soruce, $foldername) method, I get a listing of properties.  (LastModified, ModifiedTime, AccessedTime, CreatedTime, EmitTimesInWindowsFormatWhenSaving, EmitTimeInUnixFormatWhenSaving, Timestamp, Attributes, ForceNoCompression, Filename, InputStream, InputStreamWasJitProvided, Source, VersionNeeded, Comment, RequiresZip64, BitField, CompressionMethod, CompressedSize, UncompressedSize, CompressionRatio, Crc, IsDirectory, UsesEncryption, Encryption, Password, OverwriteOnExtract, ExtractExistingFile, ZipErrorAction, IncludedInMostRecentSave, WillReadTwiceOnInflation, WantCompression, UseUnicodeAsNecessary, ProvisionalAlternateEncoding, ActualEncoding, IsText)


To summarize, I want to put this all together and point the temporary zip job file to a specific drive ad hoc.  Where to do I find the property to tell the zip method where to put this temp file?


Jan 31, 2011 at 12:53 PM
Edited Feb 2, 2011 at 8:27 PM

Yes, see the TempFileFolder property. http://cheeso.members.winisp.net/DotNetZipHelp/html/84805b08-61c0-9af8-7a3a-a33d331243f8.htm

I know it's tempting to just use introspection when working with an environment like POwershell, but the documentation is pretty complete and it talks about these things.

I recommend it highly.  http://cheeso.members.winisp.net/DotNetZipHelp/frames.htm

BUT - I think you may have a misunderstanding of how the temp file works. If you are zipping up a folder, say f:\files\data , and storing that to a zipfile named c:\archives\1.zip , the temp file is created in c:\archives . There is no extra space required for temp files in c:\archives beyond the size of the zipfile itself.  If your zip is 1gb, then your temp file will start small, grow to 1gb, then DotNetZip will rename it to the final zipfile name.  So, if you have enough space to store the final zip file, then you have enough space for the temp file.  The only time a copy is performed is when you set the TempFileFolder to something other than the folder for the final zip file.  In that case DotNetZip performs a copy, which essentially doubles your space requirements for any given zip file. 

Setting TempFileFolder will not solve the problem you are describing, if I understand it correctly.  If you have enough space to store the zipfile, then you have enough space for the temp file and you shouldn't need to set TempFileFolder.  If you have enough space on f:\, then save it to f:\.  If you have enough space on g:\, then save the zipfile to g:\.  I recommend avoiding setting the TempFileFolder explicitly, unless you have some special requirement.



Feb 2, 2011 at 6:43 PM

Thanks!  I'll take another look at the setup.  Thanks for the doc link.