This script fails, error:
Convert a folder of .txt files from UTF-8 to UTF-16LE, and place the converted files into a separate folder
have a folder of 260 files created in Notebook with UTF-8 coding.
I shall need to convert these to .tif files, but the program to do this needs files with UTF-16LE coding.
How do I do the conversion to UTF-16LE with the new files placed in a different specified folder?
Thank you.
Windows for home | Windows 11 | Files, folders, and storage
2 answers
Sort by: Most helpful
-
-
Q&A Assist2026-02-17T22:22:21.56+00:00 AI generated content. This question contains an answer created with AI from Q&A Assist. Learn moreTo convert a folder of .txt files from UTF-8 to UTF-16LE and place the converted files into a separate folder, you can use PowerShell. Here's a step-by-step guide:
- Open PowerShell: You can do this by searching for "PowerShell" in the Start menu.
- Navigate to the folder containing your .txt files: Use the
cdcommand to change directories. For example:cd "C:\Path\To\Your\Folder" - Create a new folder for the converted files: You can create a new directory using the
New-Itemcommand. For example:New-Item -ItemType Directory -Path "C:\Path\To\Your\NewFolder" - Convert the files: Use a loop to convert each .txt file from UTF-8 to UTF-16LE and save it in the new folder. Here’s a sample script:
$sourceFolder = "C:\Path\To\Your\Folder" $destinationFolder = "C:\Path\To\Your\NewFolder" Get-ChildItem -Path $sourceFolder -Filter *.txt | ForEach-Object { $content = Get-Content -Path $_.FullName -Encoding UTF8 Set-Content -Path (Join-Path -Path $destinationFolder -ChildPath $_.Name) -Value $content -Encoding UTF16 }
This script retrieves all .txt files from the source folder, reads their content as UTF-8, and writes the content to new files in the destination folder using UTF-16LE encoding.
Make sure to replace
C:\Path\To\Your\FolderandC:\Path\To\Your\NewFolderwith the actual paths on your system.
References: