TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

zip files created within same month

Microsoft Windows Powershell


Reply
 
Thread Tools Display Modes
Old 26-06-2008, 04:17 PM   #1
AHartman
Guest
 
Posts: n/a
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.

  Reply With Quote
Old 26-06-2008, 04:18 PM   #2
Shay Levi
Guest
 
Posts: n/a
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


> 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.
>



  Reply With Quote
Old 26-06-2008, 04:18 PM   #3
Shay Levi
Guest
 
Posts: n/a
Re: zip files created within same month


Here's the solution using 7-Zip (



$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


> 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
>
>> 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.
>>



  Reply With Quote
Old 26-06-2008, 04:19 PM   #4
RichS [MVP]
Guest
 
Posts: n/a
Re: zip files created within same month

The PowerShell Community Extensions at


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:
PowerShell User Group:


"Shay Levi" wrote:

>
>
> 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
>
>
> > 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.
> >

>
>
>

  Reply With Quote
Old 26-06-2008, 04:19 PM   #5
Shay Levi
Guest
 
Posts: n/a
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


> The PowerShell Community Extensions at
>
> has cmdlets to write archive files as Zip, GZip, BZip2 and tar
>
> "Shay Levi" wrote:
>
>> 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
>>
>>> 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.
>>>



  Reply With Quote
Old 26-06-2008, 04:19 PM   #6
AHartman
Guest
 
Posts: n/a
Re: zip files created within same month


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


Thanks again.


"Shay Levi" <> wrote in message
news:95d8089331d288caa1c8a10b9d00@news.microsoft.c om...
>
> Here's the solution using 7-Zip (
>
>
>
> $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
>
>
>> 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
>>
>>> 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.
>>>

>
>


  Reply With Quote
Old 26-06-2008, 04:20 PM   #7
Shay Levi
Guest
 
Posts: n/a
Re: zip files created within same month


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


---
Shay Levi
$cript Fanatic


> Thanks for the script .. it will be using Pkzip.
>
> Thanks again.
>
> "Shay Levi" <> wrote in message
> news:95d8089331d288caa1c8a10b9d00@news.microsoft.c om...
>
>> Here's the solution using 7-Zip (
>>
>> $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
>>
>>> 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
>>>
>>>> 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.
>>>>



  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 04:09 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional