我用:
创建了一个新文件夹$NewPath = New-Item "\\...\newExampleFolder -ItemType directory
并使用以下内容复制旧内容:
$ OldPath = "D:\...\old.ExampleFolder"
Copy-Item $OldPath* $NewPath -recurse
现在位于新文件夹ini中。来自旧文件夹和ini文件的文件是如何引用ohter ini文件的一些路径。我想更改新文件夹的ini文件中的路径。
Example ini:
[setting1] = 1
[enginge] = 2
[setting2] = \...\old.ExampleFolder\Settings\
我试过;
$inifiles = Get-ChildItem -Path \\...\newExampleFolder\* include *.ini -
recurse
foreach($file in $inifiles)
{
(Get-Content $file.PSPath)
Foreach-Object {$file -replace
[regex]::Escape('D:\...\old.ExampleFolder\'),
('\\...\newExampleFolder\') |
set-content $file.PSPath
}
但它只改变了ini文件的内容,而不是改变了ini文件里面的Path。 我不知道有人可以帮助我吗?
答案 0 :(得分:0)
I tried this put it change only the content of the ini files in the example New Folder to the NewPath and do nothing in the supfolder $NewPath = New-Item "C:\exampleNew\exampleNew" -ItemType directory
$OldPath = "C:\exampleOld\exampleOld\"
Copy-Item $OldPath* $NewPath -recurse
$iniFile = Get-ChildItem -Path $NewPath\* -recurse -Include *.ini
ForEach($inis in $iniFile)
{
(Get-Content $inis.PSPath)
ForEach-Object {$inis -replace [regex]::Escape($OldPath),( $NewPath)}|
Set-Content $NewPath\* -Include *.ini
}