![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||