![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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. |
|
|
|
#2 |
|
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. > |
|
|
|
#3 |
|
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. >> |
|
|
|
#4 |
|
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. > > > > > |
|
|
|
#5 |
|
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. >>> |
|
|
|
#6 |
|
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. >>> > > |
|
|
|
#7 |
|
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. >>>> |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |