Remove double quotes in the content of all files

Hi, I need help removing double quotes in the content of all the files in a directory. I can get it done one file at a time not sure how to do it for all files.

(

gc C:\Temp\data.txt -En UTF8) | ForEach-Object {$_ -replace '"',''} | Out-File C:\Temp\data.txt -En UTF8

Preformatted texthen trying with all the files in a folder using below. I am not sure if I am doing it right.

Get-ChildItem "C:\Temp" -Filter *.txt | 
Foreach-Object {
    $content = Get-Content $_.FullName

    #filter and save content to the original file
    $content | % {$_ -replace '"', ''}

    #filter and save content to a new file 
    $content | Out-File $_.BaseName + '.txt' -En UTF8
}

Could you please guide me.

You’re assigning the content to a variable but you’re not updating the variable after you remove the " so you’re just writing out the content you got. See below:

Get-ChildItem "C:\Temp\" -Filter *.txt | Foreach-Object {
    
    $content = Get-Content $_.FullName  
    $content = $content -replace '"'   #Update content variable with replaced content

    #WARNING: This overwrites the files
    $content | Set-Content $_.FullName -Encoding UTF8

}

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

Thanks in advance.

https://stackoverflow.com/questions/67541373/powershell-script-to-remove-quotes-in-file

2 Likes

Hi Matt Bloomfield, Thanks very much for your response. I am now looking at minimizing the process time on these files. I will keep this space updated.

Hi Olaf, Thanks for your response. I wasn’t sure if I could share questions posted on other forums here. I’ll make sure going forward I put all the links here to make it easy.