ANSI Format File

by DaveShort at 2012-12-18 10:13:19


I’m fairly new to Powershell and have a query.

I’m currently writing a Powershell script, whereby one of the things I’m doing is taking a sequential file from an external system, and moving it to another directory (folder).

This file is in ‘ANSI’ fomat, but it seems that whenever I do a copy-item file1 file2 (or move-item), file2 then has the fomat of ‘UCS-2 Little Endian’, and this is causing a problem.

My question is, how do I copy (or move) one file to another and maintain the ANSI or ASCII format, as it seems copying files within a Powershell script, it always gives it a ‘Little Endian’ format?

I hope someone is kind enough to help me with the code for this.

by nohandle at 2012-12-18 10:28:12
That seems odd, the copy-item shan’t change file content (or even care). I just created an ANSI file and copied it. And it stayed the same. Do you make any other operation on the files?
by DaveShort at 2012-12-19 08:35:05
Thanks for the reply. I’m editing the script using Notepad++ , would this make any difference?

I’m not doing anything else with the file.

by MattG at 2012-12-19 17:08:38
Hi Dave,

I can’t seem to replicate the problem. I validated that the bytes from the source file were the same as the following via the following commands:
Get-Content -Encoding Byte .\source.txt
Copy-Item source.txt destination.txt
Get-Content -Encoding Byte .\destination.txt