-1

あなたが私の小さな問題で私を助けてくれることを願っています. A と B の 2 つの異なるフォルダーがあります。

フォルダ A には DLL のデータがたくさんあります。フォルダ B にも DLL がたくさんあります。

例えば:

フォルダ A:

ThreeServer.ホスト。v13.1 .Core.dll

こんにちは。v13.1 .Is.More.dll

フォルダ B:

ThreeServer.ホスト。v12.0 .Core.dll

こんにちは。v12.0 .Is.More.dll

フォルダー A 内のすべての DLL の名前は、"v13.1" とフォルダー B (v12.0) 内の DLL の名前が異なるだけです。

ここで、フォルダー A 内のすべての DLL をフォルダー B 内の DLL に置き換えたいと考えています。

すべてが言語PowerShellISE/Powershellに基づいています。

これまたは methode の解決策を知っている人はいますか?

4

2 に答える 2

1

の組み合わせを使用しGet-ChildItemてファイル リストを取得し、正規表現を使用してファイル名のバージョン以外の部分を取得し、次にワイルドカードを使用して宛先ディレクトリに一致があるかどうかを確認します。

Get-ChildItem -Path $DLLPath -Filter *.dll |
    Where-Object { $_.BaseName -Match '^(.*)(v\d+\.\d+)(.*)$' } |
    Where-Object { 
        # uses $matches array to check if corresponding file in destination
        $destFileName = '{0}*{1}.dll' -f $matches[1],$matches[3]
        $destinationPath = Join-Path $FolderB $destFileName

        # Add the destination file name mask to the pipeline object so we can use it later
        $_ | Add-Member NoteProperty -Name DestinationPath -Value $destinationPath

        # Check that a corresponding destination exists
        Test-Path -Path $_.DestinationPath -ItemType Leaf
    } | 
    Copy-Item -WhatIf -Verbose -Destination { 
        # Use Get-Item to get the actual file matching the wildcard above.
        # But only get the first one in case there are multiple matches.
        Get-Item $_.DestinationPath | Select-Object -First 1 -ExpandProperty FullName
    }  

正規表現の詳細については、 about_Regular_Expressionsを参照してください。

于 2013-07-04T12:44:44.613 に答える