I have used 7zip as a command line compression tool. http://www.7-zip.org/
Following script compresses all files that match specific file pattern e.g. *.txt, *.doc, *.png etc.
It should also work with Universal Naming Convention(UNC) Paths. e.g.
file://10.10.10.63/SharedDocs/archive.zip etc.
$Path = $(Read-Host "Enter Path and file pattern e.g. c:\zip\*.txt")
$Files = get-childitem $Path -include $Pattern -recurse
$FileNames = ""
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
$FileNames = $FileNames + " " + $File
}
write-host "Files to compress : " $FileNames
if($FileNames.Trim() -ne "")
{
powershell.exe -noexit "&'c:\program files\7-zip\7z'" a c:\target\archive.zip $FileNames
}
else
{
write-host "No files to compress :D"
}
No comments:
Post a Comment