-1

How can I change this script so that will only compresses the files that are older than 7 days?

FOR %%A IN (D:\Agentrics\integration\incoming\Mansoor\backup\*.txt*, D:\Agentrics\integration\incoming\Mansoor\backup\*.cpi*) DO "C:\Program Files\WinRAR\WinRAR.exe" a -r D:\Agentrics\integration\incoming\Mansoor\backup\"%%~nA.zip" "%%A"

FOR %%A IN (D:\Agentrics\integration\incoming\Mansoor\backup\*.TXT,D:\Agentrics\integration\incoming\Mansoor\backup\*.cpi) DO DEL "D:\Agentrics\integration\incoming\Mansoor\backup\.cpi*" "%%A"

Regards, Jason

4

2 回答 2

3

只需使用WinRAR's-to开关,它指示归档程序仅处理早于指定时间段的文件。句点应该是由数值和单位组成的字符串:

NNNdNNNhNNNmNNNs

其中NNN's 是数值,d(days), h(hours), m(minutes), s(seconds) 是有效的单位指示符。

您不必指定所有单位。例如,在您的情况下,期间将是7d

FOR %%A IN (
  D:\Agentrics\integration\incoming\Mansoor\backup\*.txt*
  D:\Agentrics\integration\incoming\Mansoor\backup\*.cpi*
) DO (
  "C:\Program Files\WinRAR\WinRAR.exe" a -r -to7d D:\Agentrics\integration\incoming\Mansoor\backup\"%%~nA.zip" "%%A"
)

如果没有文件与指定的时间段匹配,则不会创建/更新存档。

于 2013-02-28T22:28:43.013 回答
2

Robocopy 能够根据年龄复制文件。我会使用 robocopy 将文件移动到一个临时目录,然后压缩该目录的内容。

例如(未经测试):

SET SourceDir=C:\Agentrics\integration\incoming\Mansoor\backup
SET TmpDir=C:\Agentrics\integration\incoming\Mansoor\backup\tmpbackup

ROBOCOPY "%SourceDir%" "%TmpDir%" *.txt *.cpi /MOV /MINAGE:7 
FOR %%A IN (%TmpDir%\*.*) DO "C:\Program Files\WinRAR\WinRAR.exe" a "%SourceDir%\%%~nA.zip" "%%A" 
RMDIR /S /Q "%TmpDir%"
于 2013-02-28T19:06:05.017 回答