开发者

Create a 7z Archive for files created by date using Powershell

I have directory where various daily files gets copied. I need to write a power shell script which will create 7z archive based on grou开发者_运维百科ps of file create date.The name of the archive includes those group dates.

Example Below

FileA  06/23/11
FileB  06/23/11
FileC  06/24/11

Script should create 2 archives

062311.7z contains FileA, FileB
062411.7z contains FileC

Thanks in advance

--------- Now I have to develop a compression routine which can take care of daily/Weekly/ Monthly durations


The first thing you need to do is group all the files via date using group-object:

$groups = dir | group-object -property {$_.LastWriteTime.Date}

then for each group, build a command string that does your zipping and execute it:

$groups | foreach{$cmd = "7z.exe a $((Get-Date $_.Name).ToString(`"MMddyy`")).7z $([string]::join(`" `", $_.Group))"; invoke-expression $cmd}

Warning, the above is not really tested (for ex. it won't work if you spaces in your filename). But hopefully, it will give you enough to proceed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜