How to zip single files each in their own zip file

Sep 10, 2009 at 3:10 PM

I have spent hours trying to figure this out, and it's something that is soooo simple with wzzip.  I simply want to take a group of files and zip them up one at a time, each in their own zip file.  But when I open the zip file, I only want that one file in there with NO directory tree.  Any help would be greatly apprecitated.

Here's my powershell script (at least the dotnetzip portion) with it as close as I could get it.  I don't want the $MysteriousFolderName in there at all, but that's all I could figure out:

 

foreach ($file in gci $LogPath -filter $FileType -recurse | where{$_.LastWriteTime -lt [DateTime]::Now.AddDays($DaysOld)})
    {
        $FileName = $File.FullName
        $ZipName = $File.FullName + ".zip"
        $MysteriousFolderName = ($File.DirectoryName).split("\")
        $directoryToZip = $File.DirectoryName
        
        $zipfile =  new-object Ionic.Zip.ZipFile
        $e = $zipfile.AddSelectedFiles($FileName, $directoryToZip, $MysteriousFolderName[5])
        $zipfile.Save($ZipName)
        $zipfile.Dispose()
    }

Thanks,
Gary

 

foreach ($file in gci $LogPath -filter $FileType -recurse | where{$_.LastWriteTime -lt [DateTime]::Now.AddDays($DaysOld)})
    {
        $FileName = $File.FullName
        $ZipName = $File.FullName + ".zip"
        $MysteriousFolderName = ($File.DirectoryName).split("\")
        $directoryToZip = $File.DirectoryName
        
        $zipfile =  new-object Ionic.Zip.ZipFile
        $e = $zipfile.AddSelectedFiles($FileName, $directoryToZip, $MysteriousFolderName[5])
        $zipfile.Save($ZipName)
        $zipfile.Dispose()
    }

 

 

Coordinator
Sep 10, 2009 at 3:20 PM
foreach ($file in gci $LogPath -filter $FileType -recurse | where{$_.LastWriteTime -lt [DateTime]::Now.AddDays($DaysOld)})
{
    $FileName = $File.FullName
    $ZipName = $File.FullName + ".zip"
    $zip = new-object Ionic.Zip.ZipFile
    $zip.AddFile($FileName, "");
    $zip.Save($ZipName)
    $zip.Dispose()
}
Sep 10, 2009 at 4:03 PM

Thank you so much, that worked perfectly!

Gary