0

I created a basic Powershell script that has a simple objective :

  1. copy all files from a folder to another folder
  2. remove BOM from those files
  3. rename files

For this I created a simple script :

# input & ouput folders
$inputFolder  = 'C:\Users\myName\myInputFolder'
$outputFolder = 'C:\Users\myName\myOutputFolder'

# move files
Copy-item -Force -Recurse -Verbose $inputFolder\* -Destination $outputFolder

# remove bom to files
Get-ChildItem $outputFolder\*  -recurse -Include *.json,*.html,*.xml,*.js,*.txt,*.css | ForEach-Object {
   $content = $_ | Get-Content
   Set-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force
}

# rename files
Get-ChildItem -Path $outputFolder\*.txt | Rename-Item -NewName { $_.Name -replace '.txt','.done.txt' }

My question is how to check if that I correctly removed the BOM from those files.

davidvera
  • 673
  • 11
  • 29

1 Answers1

0

One solution is the following :

foreach ($i in ls -name $inputFolder\*.txt)
{
    $file_content = Get-Content "$inputFolder\$i";
    [System.IO.File]::WriteAllLines("$outputFolder\$i", $file_content);
}
davidvera
  • 673
  • 11
  • 29