I need to merge all txt-files in a certain folder on my computer. There's hundreds of them and they all have a different name, so any code where you had to manually type the name of the files in order to merge them was not working for me. The files are in "UTF-8"-encoding and contain emojis and characters from different languages (such as Cyrillic script) as well as characters with accents and so on (e.g. é, ü, à...). A fellow stackoverflow-user was so kind as to give me the following code to run in Powershell:
(gc *.txt) | out-file newfile.txt -encoding utf8
It works wonderfully for merging the files. However, it actually gives me a txt-file with "UTF-8 with BOM"-encoding, instead of with "UTF-8"-encoding. Furthermore, all emojis and special characters have been removed and exchanged for others, such as "ü" instead of "ü". It is very importatnt for what I am doing that these emojis and special characters remain.
Could someone help me with tweaking this code (or suggesting a different one) so it gives me a merged txt-file with "UTF-8"-encoding that still contains all of the special characters? Please keep in mind that I am a layperson.
Thank you so much in advance for your help and kind regards!
UTF8NoBOM?Get-Contentalso supports encoding specification, which the sample doesn't utilize.(gc *.txt) | out-file newfile.txt -encoding UTF8NoBOMonly gives me an error that:Out-File: Cannot validate argument on parameter 'Encoding'. The argument "UTF8NoBOM" does not belong to the set "unknown;string;unicode;bigendianunicode;utf8;utf7;utf32;ascii;default;oem" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.Get-Content? Try also a work-around via .Net.(gc *.txt) | out-file newfile.txt -encoding UTF8. If that is what you mean then unfortunately it didn't work. It always gives me a txt-file with "UTF-8 with BOM". I looked at the work-around (thank you!) you sent me, but there's a lot of information there and I'm not really sure what to use.