简体   繁体   English

使用Powershell为按日期创建的文件创建7z存档

[英]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 groups of file create date.The name of the archive includes those group dates. 我需要编写一个Power Shell脚本,该脚本将基于文件创建日期的组创建7z存档。存档的名称包括这些组日期。

Example Below 下面的例子

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

Script should create 2 archives 脚本应创建2个档案

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. 但希望它会给您足够的继续进行的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM