Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

replace content of specific file in a directory

$
0
0

Hi PowerShell Guru's,

I have an issue like this:

Suppose in a folder i have 3 different type of files:

Line.txt

Line.sql

Line.htm

I have the following code:

$configFiles=get-childitem . *.xml -rec

foreach ($file in $configFiles)

{
(Get-Content $file.PSPath) |
Foreach-Object {$_-replace 'Pro', 'Product'}|
Set-Content $file.PSPath
}

 

which means when i run the code on this folder, it will search for all the words pro and replaced it by product.

What if I want only to do the change in the line.txt file only?

I tried this code but no outcome :

$configFiles=get-childitem . *.xml -rec

foreach ($file in $configFiles)

{
(Get-Content $file.PSPath) |

Foreach-Object
where-object {$_.extension -ne "*.sql*", "*.htm*"} 
Foreach-Object {$_-replace 'Pro', 'Product'}|
Set-Content $file.PSPath
}

 

can you suggest me something or help me out with the code please

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles