/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" get a Users LastLogontime and Domaincontroller fro... "," Some fun With Monads Add-Member, MP3 files and COM... "," MSH snap-in to Translate IADsLargeInteger to Int64... "," Commandline editing with MSH. "," MSH Scroll-host function "," Series about Monad on Computerworld "," Watching FSRM Quota and filescreen events from Mon... "," More ACL and MSH on MSH for Fun "," Jelle "," Monad and "Jeugd sentiment" "," ")

Thursday, January 26, 2006


MSH out-zip Function

This function will add files to a "Compressed (zipped) Folder" or will make a new ZIP file if the file does not exists.

you can use the Shell.application COM Object to add files or folders to a Compressed folder, so you can also use the CopyGUI ScriptMethod from Update-TypeData (Democracy to the types) , to add files or folders to a ZIP file, as this uses this object also.

(gi test.txt).CopyGUI("c:\mow.zip")

MSH>(gi .).copygui

Script              : $name= $args[0]
                                      #$target = (read-host "Enter Target: ")
                                      $(new-object -com shell.application).NameSpace($name).CopyHere($this.fullname)
                                      trap {"Error Copying"continue }
OverloadDefinitions : {System.Object CopyGUI();}
MemberType          : ScriptMethod
TypeOfValue         : System.Object
Value               : System.Object CopyGUI();
Name                : CopyGUI
IsInstance          : False

But only if this ZIP file does already exist.

the Out-Zip function will also Create a New ZIP file (Compressed Folder) , if it does not exist.

I made it to take file or directory objects from the pipeline so you can use it like this :

# add all textfiles in Dir to Mow.zip
ls *.txt | out-zip c:\mow.zip

#add Monad directory to zipfile
cd g:\monad
gi . | outzip c:\mow.zip

(more like a filter)

the script looks like this :

# Out-Zip.msh
# creates out-Zip function
# /\/\o\/\/ 2006   
# http://mow001.blogspot.com

function out-zip {

  if (-not $path.EndsWith('.zip')) {$path += '.zip'}

  if (-not (test-path $path)) {
    set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
  $ZipFile = (new-object -com shell.application).NameSpace($path)
  $input | foreach {$zipfile.CopyHere($_.fullname)}


gr /\/\o\/\/

Tags :

Comments: Post a Comment

Links to this post:

Create a Link

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?