Hi powershell friends,
I am having no luck sorting this problem out. :(
I have a CSV file Set Out Like this
FindString ____ReplaceString____FileName
X1_____________123_____________1.txt
X1_____________389_____________2.txt
X1_____________098_____________3.txt
I am doing find and replacements in specific files in column C.
taken from:
http://powershell.org/wp/forums/topic/script-to-find-replace-multiple-strings-in-multiple-text-files-using-powershell/
$FolderLocation = 'C:\Users\PW\Desktop\a\'
$oFiles = Get-ChildItem -Path $FolderLocation\*.txt | ForEach-Object FullName
$findReplaceList = Import-Csv -Path $FolderLocation\a.csv # CSV file
$totalitems = $oFiles.count
$currentrow = 0
foreach ($oTxtFile in $oFiles)
{
$currentrow += 1
Write-Progress -Activity "Processing record $currentrow of $totalitems" -Status "Progress:" -PercentComplete (($currentrow / $totalitems) * 100)
[string] $txtFile = Get-Content $oTxtFile | Out-String
#### ADD COLUMN C - which has the filename
# ForEach ($FileName in $findReplaceList)
ForEach ($findReplaceItem in $findReplaceList)
{
$txtFile = $txtFile -replace "$($findReplaceitem.FindString)", "$($findReplaceitem.ReplaceString)"
}
$txtFile | Set-Content ($oTxtFile)
}
I have tried a lot of things and i cant get this to work :( :(
Where do I add column C - File Name so that the script will pick it up
thank you for your help
pw
I am having no luck sorting this problem out. :(
I have a CSV file Set Out Like this
FindString ____ReplaceString____FileName
X1_____________123_____________1.txt
X1_____________389_____________2.txt
X1_____________098_____________3.txt
I am doing find and replacements in specific files in column C.
taken from:
http://powershell.org/wp/forums/topic/script-to-find-replace-multiple-strings-in-multiple-text-files-using-powershell/
$FolderLocation = 'C:\Users\PW\Desktop\a\'
$oFiles = Get-ChildItem -Path $FolderLocation\*.txt | ForEach-Object FullName
$findReplaceList = Import-Csv -Path $FolderLocation\a.csv # CSV file
$totalitems = $oFiles.count
$currentrow = 0
foreach ($oTxtFile in $oFiles)
{
$currentrow += 1
Write-Progress -Activity "Processing record $currentrow of $totalitems" -Status "Progress:" -PercentComplete (($currentrow / $totalitems) * 100)
[string] $txtFile = Get-Content $oTxtFile | Out-String
#### ADD COLUMN C - which has the filename
# ForEach ($FileName in $findReplaceList)
ForEach ($findReplaceItem in $findReplaceList)
{
$txtFile = $txtFile -replace "$($findReplaceitem.FindString)", "$($findReplaceitem.ReplaceString)"
}
$txtFile | Set-Content ($oTxtFile)
}
I have tried a lot of things and i cant get this to work :( :(
Where do I add column C - File Name so that the script will pick it up
thank you for your help
pw