Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - zip files created within same month

Reply
 
Old 06-20-2008   #1 (permalink)
AHartman


 
 

zip files created within same month

I have an archive folder that contains files from different months. I would
like to have a script that takes all of the files created say in May and
creates a zip file called May2008.zip. Then after it creates the zip and
verifies delete the files from the folder. Then does the same for and other
previuos months files.


TIA.


My System SpecsSystem Spec
Old 06-21-2008   #2 (permalink)
Shay Levi


 
 

Re: zip files created within same month



What ZIP application do you use?

This will dir files only, group them by the month/year they were created.


dir d:\scripts\temp | where {!$_.PSIsContainer} | group {"{0:MMM}{0:yyyy}"
-f $_.CreationTime} | foreach {
$zipFileName = $_.name + ".zip"
# make zip file $zipFileName
$_.group | Remove-Item -WhatIf
}


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I have an archive folder that contains files from different months. I
> would like to have a script that takes all of the files created say in
> May and creates a zip file called May2008.zip. Then after it creates
> the zip and verifies delete the files from the folder. Then does the
> same for and other previuos months files.
>
> TIA.
>

My System SpecsSystem Spec
Old 06-21-2008   #3 (permalink)
RichS [MVP]


 
 

Re: zip files created within same month

The PowerShell Community Extensions at
http://www.codeplex.com/Wiki/View.as...e=PowerShellCX

has cmdlets to write archive files as Zip, GZip, BZip2 and tar

--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Shay Levi" wrote:
Quote:

>
>
> What ZIP application do you use?
>
> This will dir files only, group them by the month/year they were created.
>
>
> dir d:\scripts\temp | where {!$_.PSIsContainer} | group {"{0:MMM}{0:yyyy}"
> -f $_.CreationTime} | foreach {
> $zipFileName = $_.name + ".zip"
> # make zip file $zipFileName
> $_.group | Remove-Item -WhatIf
> }
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > I have an archive folder that contains files from different months. I
> > would like to have a script that takes all of the files created say in
> > May and creates a zip file called May2008.zip. Then after it creates
> > the zip and verifies delete the files from the folder. Then does the
> > same for and other previuos months files.
> >
> > TIA.
> >
>
>
>
My System SpecsSystem Spec
Old 06-21-2008   #4 (permalink)
Shay Levi


 
 

Re: zip files created within same month


Here's the solution using 7-Zip (www.7-zip.org):



$7z = "C:\Program Files\7-Zip\7z.exe"

dir d:\scripts\temp | where {!$_.PSIsContainer} | group {"{0:MMM}{0:yyyy}"
-f $_.CreationTime} | foreach {

$zipFileName = $_.name + ".zip"

# generate list of files to compress, for list files, 7-Zip uses UTF-8 encoding
by default
$_.group | foreach {$_.fullname} | out-file d:\listfile.txt -encoding utf8
-force

# archive list of files
$null = & $7z a -tzip d:\$zipFileName `@d:\listfile.txt

# check if the operation succeeded
if($LASTEXITCODE -eq 0){
"operation succeeded, removing source files..."
$_.group | Remove-Item -whatIf
} else {
"error"
}

}




---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> What ZIP application do you use?
>
> This will dir files only, group them by the month/year they were
> created.
>
> dir d:\scripts\temp | where {!$_.PSIsContainer} | group
> {"{0:MMM}{0:yyyy}"
> -f $_.CreationTime} | foreach {
> $zipFileName = $_.name + ".zip"
> # make zip file $zipFileName
> $_.group | Remove-Item -WhatIf
> }
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> I have an archive folder that contains files from different months. I
>> would like to have a script that takes all of the files created say
>> in May and creates a zip file called May2008.zip. Then after it
>> creates the zip and verifies delete the files from the folder. Then
>> does the same for and other previuos months files.
>>
>> TIA.
>>

My System SpecsSystem Spec
Old 06-21-2008   #5 (permalink)
Shay Levi


 
 

Re: zip files created within same month


Thanks Rich, much better


dir d:\scripts\temp | where {!$_.PSIsContainer} | group {"{0:MMM}{0:yyyy}"
-f $_.CreationTime} | foreach {
write-zip -path ($_.group | foreach {$_.fullname} ) -OutputPath ($_.name
+ ".zip") -removeoriginal -whatIf
}




---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> The PowerShell Community Extensions at
> http://www.codeplex.com/Wiki/View.as...e=PowerShellCX
> has cmdlets to write archive files as Zip, GZip, BZip2 and tar
>
> "Shay Levi" wrote:
>
Quote:

>> What ZIP application do you use?
>>
>> This will dir files only, group them by the month/year they were
>> created.
>>
>> dir d:\scripts\temp | where {!$_.PSIsContainer} | group
>> {"{0:MMM}{0:yyyy}"
>> -f $_.CreationTime} | foreach {
>> $zipFileName = $_.name + ".zip"
>> # make zip file $zipFileName
>> $_.group | Remove-Item -WhatIf
>> }
>> ---
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I have an archive folder that contains files from different months.
>>> I would like to have a script that takes all of the files created
>>> say in May and creates a zip file called May2008.zip. Then after it
>>> creates the zip and verifies delete the files from the folder. Then
>>> does the same for and other previuos months files.
>>>
>>> TIA.
>>>

My System SpecsSystem Spec
Old 06-21-2008   #6 (permalink)
AHartman


 
 

Re: zip files created within same month


Thanks for the script .. it will be using Pkzip.


Thanks again.


"Shay Levi" <no@xxxxxx> wrote in message
news:95d8089331d288caa1c8a10b9d00@xxxxxx
Quote:

>
> Here's the solution using 7-Zip (www.7-zip.org):
>
>
>
> $7z = "C:\Program Files\7-Zip\7z.exe"
>
> dir d:\scripts\temp | where {!$_.PSIsContainer} | group
> {"{0:MMM}{0:yyyy}" -f $_.CreationTime} | foreach {
>
> $zipFileName = $_.name + ".zip"
>
> # generate list of files to compress, for list files, 7-Zip uses UTF-8
> encoding by default
> $_.group | foreach {$_.fullname} | out-file d:\listfile.txt -encoding
> utf8 -force
>
> # archive list of files
> $null = & $7z a -tzip d:\$zipFileName `@d:\listfile.txt
>
> # check if the operation succeeded
> if($LASTEXITCODE -eq 0){
> "operation succeeded, removing source files..."
> $_.group | Remove-Item -whatIf
> } else {
> "error"
> }
>
> }
>
>
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> What ZIP application do you use?
>>
>> This will dir files only, group them by the month/year they were
>> created.
>>
>> dir d:\scripts\temp | where {!$_.PSIsContainer} | group
>> {"{0:MMM}{0:yyyy}"
>> -f $_.CreationTime} | foreach {
>> $zipFileName = $_.name + ".zip"
>> # make zip file $zipFileName
>> $_.group | Remove-Item -WhatIf
>> }
>> ---
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I have an archive folder that contains files from different months. I
>>> would like to have a script that takes all of the files created say
>>> in May and creates a zip file called May2008.zip. Then after it
>>> creates the zip and verifies delete the files from the folder. Then
>>> does the same for and other previuos months files.
>>>
>>> TIA.
>>>
>
>
My System SpecsSystem Spec
Old 06-21-2008   #7 (permalink)
Shay Levi


 
 

Re: zip files created within same month


What version? Check my reply to RichS. PSCX is much more robust solution.


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Thanks for the script .. it will be using Pkzip.
>
> Thanks again.
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:95d8089331d288caa1c8a10b9d00@xxxxxx
>
Quote:

>> Here's the solution using 7-Zip (www.7-zip.org):
>>
>> $7z = "C:\Program Files\7-Zip\7z.exe"
>>
>> dir d:\scripts\temp | where {!$_.PSIsContainer} | group
>> {"{0:MMM}{0:yyyy}" -f $_.CreationTime} | foreach {
>>
>> $zipFileName = $_.name + ".zip"
>>
>> # generate list of files to compress, for list files, 7-Zip uses
>> UTF-8
>> encoding by default
>> $_.group | foreach {$_.fullname} | out-file d:\listfile.txt -encoding
>> utf8 -force
>> # archive list of files
>> $null = & $7z a -tzip d:\$zipFileName `@d:\listfile.txt
>> # check if the operation succeeded
>> if($LASTEXITCODE -eq 0){
>> "operation succeeded, removing source files..."
>> $_.group | Remove-Item -whatIf
>> } else {
>> "error"
>> }
>> }
>>
>> ---
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> What ZIP application do you use?
>>>
>>> This will dir files only, group them by the month/year they were
>>> created.
>>>
>>> dir d:\scripts\temp | where {!$_.PSIsContainer} | group
>>> {"{0:MMM}{0:yyyy}"
>>> -f $_.CreationTime} | foreach {
>>> $zipFileName = $_.name + ".zip"
>>> # make zip file $zipFileName
>>> $_.group | Remove-Item -WhatIf
>>> }
>>> ---
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> I have an archive folder that contains files from different months.
>>>> I would like to have a script that takes all of the files created
>>>> say in May and creates a zip file called May2008.zip. Then after it
>>>> creates the zip and verifies delete the files from the folder. Then
>>>> does the same for and other previuos months files.
>>>>
>>>> TIA.
>>>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Files Created for Virtual Server Virtual Server
Files created by Powershell are over 2X bigger than files created bytext editor or cmd.exe. PowerShell
.tmp files created when using off-line folders Vista file management
Files created during upgrade from XP Vista file management
Cannot access files created with XP Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46