Share via

Convert a folder of .txt files from UTF-8 to UTF-16LE, and place the converted files into a separate folder

velson Horie 0 Reputation points
2026-02-17T22:22:02.3533333+00:00

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
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. velson Horie 0 Reputation points
    2026-02-17T22:42:13.6966667+00:00

    This script fails, error:

    User's image


  2. Q&A Assist
    2026-02-17T22:22:21.56+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To 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:

    1. Open PowerShell: You can do this by searching for "PowerShell" in the Start menu.
    2. Navigate to the folder containing your .txt files: Use the cd command to change directories. For example:
         cd "C:\Path\To\Your\Folder"
      
    3. Create a new folder for the converted files: You can create a new directory using the New-Item command. For example:
         New-Item -ItemType Directory -Path "C:\Path\To\Your\NewFolder"
      
    4. 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\Folder and C:\Path\To\Your\NewFolder with the actual paths on your system.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.