2017-07-13 6 views
0

私はlitleスクリプトwathの変更を行いました。iniファイルのパスは、フォルダーとフォルダーのサブフォルダーにあります。だから私の問題は、\D:\example\のパスと/F:/example/のパスがあることがわかります。私のスクリプトは/を含めるには\とi trieだけを変更しますが、失敗します。手伝って頂けますか?ここでiniテキスト内でのパスの編集

私のスクリプト

<# here i create a new folder with the folder dialog #> 
Ad-Type-AssemblyName 
syste,-windows.Forms 
$browser = New-Object system.windows.Forms.FolderBrowserDialog 
$browser.Description " Make A New Folder 
$null = $browser.showDialog() 
$browser = $NewPath 

<# here i select a folder what i want to copy with the folder dialog #> 
Ad-Type-AssemblyName 
syste,-windows.Forms 
$browser = New-Object system.windows.Forms.FolderBrowserDialog 
$browser.Description " Make A New Folder 
$null = $browser.showDialog() 
$browser = $OldPath 

<# Here i copy the old in the new folder #> 
Copy-Item $OldPath\* $NewPath -recurse 

<# Here i replace the old Paths with backslashes in the ini files (they are in the text of the ini file) with the new #> 

$ChangePath = $OldPath 
$iniFile = Get-ChildItem -Path "$NewPath/* include *.ini -recurse 
ForEach($file in $iniFile){ 
    (Get-Content $file)-replace [regex]::Escape($ChangePath),($NewPath) | Set-Content - Path $file.FullName 

<# this uper the comment work but now come what doesnt work #> 
<# here i try to replace all paths in the text of the ini file with a normal slash "/" #> 

$changePath2 = $OldPath 
($changePath2 -replace [regex]::Escape ('\'),('/')) 
$NewPath = $NewPath 
($NewPath2 -replace [regex]::Escape ('\'),('/')) 
$iniFile2 = Get-ChildItem -Path "$NewPath/* include *.ini -recurse 
ForEach($file2 in $iniFile2){ 
    (Get-Content $file2)-replace [regex]::Escape($ChangePath2),($NewPath2) | Set-Content - Path $file2.FullName 

このdoesntの仕事、それは私がフォルダとサブフォルダ内のすべてのiniファイルを読まなければならないので、それはより多くの時間が必要に働くだろう。 2回ではなく1回行う方法はありますか?あなたが私を助けることができないときは、それは素晴らしいでしょう。

答えて

0

PowerShellの-replaceを使用して、バックスラッシュからエスケープするだけで済みます。例:"\\\" -replace "\\","/"が返される///

関連する問題