我试图提取约40个文件夹,每个包含一个RAR,但我从来没有做过PowerShell。 在bash中,你可以使用*/*.rar来使用通配符来提取它们,但是我如何在powershell中这样做呢? 我尝试了一些东西
C:\Program Files (x86)\Unrar\UnRAR.exe' x .\*\*.rar
但它错误:
UNRAR 4.10 freeware Copyright (c) 1993-2012 Alexander Roshal Cannot read contents of .\*\*.rar The filename, directory name, or volume label syntax is incorrect.
我使用这个:
$parent = 'c:\myrar_files' $files = @() Get-ChildItem $parent -Recurse -Filter "*.rar" | % { # Recurse through all subfolders looking for .rar files only. $files = $files + $_.FullName } foreach ($f in $files) { # UnRAR the files. -y responds Yes to any queries UnRAR may have. C:\scripts\WinRAR\unrar x -y $f }
先testing一下,因为我没有任何东西可以testing :
get-childitem -recurse -filter *.rar | %{"C:\Program Files (x86)\Unrar\UnRAR.exe" x $_.fullpath}
我不是100%确定,如果x将导致它提取到当前目录或rar文件的目录,所以你可能不得不添加一个cd到命令。
get-childitem -recurse -filter *.rar | %{cd $_.directory; "C:\Program Files (x86)\Unrar\UnRAR.exe" x $_.name}