[英]Adding Multiple files into Winrar archive with Powershell
I have a script that used to work and add multiple files to a Winrar archive, test the archive, then delete the original files. 我有一个脚本,该脚本用于工作并将多个文件添加到Winrar存档,测试存档,然后删除原始文件。 It worked great, then I broke it, and now cannot fix.
效果很好,后来我弄坏了,现在无法修复。 problem now is that for each file I am adding to the archive, a new Winrar window pops up and tells me that a file is in use by another process.
现在的问题是,对于我要添加到存档中的每个文件,都会弹出一个新的Winrar窗口,并告诉我该文件正在被另一个进程使用。
The powershell here is likely fine, but I think i'm doing something wrong with the rar command and/or the paths. 这里的powershell可能不错,但是我认为rar命令和/或路径做错了。
thanks in advance for any suggestions. 在此先感谢您的任何建议。
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}
First, you should use $file.fullname
instead of $path\\$file
, for better practice. 首先,您应该使用
$file.fullname
而不是$path\\$file
,以获得更好的实践。 And second, use rar.exe
not winrar.exe
to archive via command line, because rar.exe
is a console application, and it does not release the script to continue to the next file until this file would be added to the archive. 其次,使用
rar.exe
而不是winrar.exe
通过命令行进行归档,因为rar.exe
是一个控制台应用程序,它不会释放脚本以继续到下一个文件,直到将该文件添加到归档文件中为止。 Also it might be needed to use &
before rar
. 此外,它可能需要使用
&
之前rar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.