使用Powershell将多个文件添加到Winrar存档中

时间:2015-07-30 02:41:50

标签: powershell winrar

我有一个脚本,用于工作并将多个文件添加到Winrar存档,测试存档,然后删除原始文件。它工作得很好,然后我打破了它,现在无法解决。 现在的问题是,对于我要添加到存档的每个文件,会弹出一个新的Winrar窗口并告诉我另一个进程正在使用该文件。

这里的powershell很可能,但我认为我对rar命令和/或路径做错了。

提前感谢任何建议。

    set-alias rar "c:\Program Files\WinRAR\WinRAR.exe"
$startdate = get-date("7/20/2015 00:00")
$enddate = get-date("7/21/2015 00:00")
$path = "D:\TFS.Backup"
$files = Get-ChildItem $path | Where-Object {$_.creationtime -gt $startdate -and $_.creationtime -lt $enddate}
$filedate = $startdate.day
$fileyear = $startdate.year
$filemonth = $startdate.month
$rarname = "$fileyear-$filemonth-$filedate.rar"
$destination = "$path\archive"
foreach ($file in $files) {rar  a -r -m3 -t -df -mt4 $destination\$rarname $path\$file}

1 个答案:

答案 0 :(得分:0)

首先,您应该使用$file.fullname代替$path\$file,以便更好地练习。第二,使用rar.exe而不是winrar.exe通过命令行进行存档,因为rar.exe是一个控制台应用程序,并且它不会释放脚本以继续下一个文件,直到此文件为止添加到存档。此外,可能需要在&之前使用rar

相关问题