2012-03-13 4 views
2

私は補完的な.md5ファイルを持つファイルのリストを取得する必要があるPowerShellスクリプトを作成しています。たとえば、ファイル名がabc.txtの場合、同じディレクトリにabc.txt.md5という名前のファイルが存在する場合にのみ、リストに追加します。PowerShellの.md5対応のすべてのファイルのリストを取得

これは私の試みですが、動作しません。なぜわからないのですか?

$DirectoryToScan = ".\SomePath" 
$Files = Get-ChildItem $DirectoryToScan -Recurse | 
    Where-Object { !$_.PSIsContainer } | 
    Where-Object { $_.Name -notmatch ".*\.md5" } | 
    Where-Object { Test-Path "$($_.FullName).md5" } 

最後のWhere-Object節がなければ問題なく動作します。私はこれが動作し、あなたがテストパスのために再びディレクトリを打つ保存するべきだと思い

gci $DirectoryToScan -recurse -exclude "*.md5" | ?{ -not $_.PsIsContainer } | 
     ?{ test-path ($_.fullname + ".md5") } 

答えて

2

は私のために仕事をしていますが、このような何かをやって試すことができます。

$DirectoryToScan = ".\SomePath" 
$temp = Get-Childitem $DirectoryToScan -recurse | select -expand fullname 
$files = $temp | 
foreach {if ($_ -notmatch '\.md5$' -and $temp -contains "$_.md5"){$_}} 
+0

恥ずかしい...私はただの.md5ファイルなしディレクトリに対してスクリプトを実行された可能性があります。私はその簡潔さのためにあなたのスクリプトが好きです。 –

1

:あなたが与えるを持っていた何

1
Get-ChildItem $DirectoryToScan -Recurse | ` 
    Where-Object { !$_.PSIsContainer -and (Test-Path "$($_.FullName).md5" -PathType Leaf)} 
関連する問題