title: batch: add a unicode header or how to add hex values or any other ways around this?
body: <p>I have a batch script that uses drag and drop and creates some html code based on the filenames of the dropped files/folders. 
  With </p>
  
  <pre><code>chcp 65001
  </code></pre>
  
  <p>I get this to write unicode. All fine and well. In the notepad editor at least, while the browser only shows garbage. When I re-save the file in notepad the file will work all fine in the browser, too. 
  Unfortunately it seems the created unicode file is missing two "unicode header" characters (0xFF and 0xFE), right before the file, as comparison with hexdump (<a href="http://www.fileformat.info/tool/hexdump.htm" rel="nofollow noreferrer">http://www.fileformat.info/tool/hexdump.htm</a>) yielded as a result.</p>
  
  <p>On this topic I found this: 
  <a href="http://www.robvanderwoude.com/type.php#Unicode" rel="nofollow noreferrer">http://www.robvanderwoude.com/type.php#Unicode</a></p>
  
  <p>The linked file from there sorts of doesn't work (parameter format error) Examples from this site on non-native echos etc. are out of the question. Copying an empty unicodeHeader-Helper File and appending my file works fine, but is very suboptimal, since it would mean, any folder, from which my files are drag and droped would need to have this helper file in. Which is not assumed to be the case as it is unpractical, so that is no good. </p>
  
  <p>Using type is also out of the question, as it creates a whole lot of whitespaces between the characters.</p>
  
  <p>So I was thinking of writing the file with missing header into a temp file, add the two hex values into a file and append the temp file to it. So basically writing the hex chars directly instead of copying them from the empty unicode helper file.</p>
  
  <p>I found this:
  <a href="http://www.dostips.com/forum/viewtopic.php?f=3&amp;t=3857" rel="nofollow noreferrer">http://www.dostips.com/forum/viewtopic.php?f=3&amp;t=3857</a>
  and moreover this:
  <a href="https://stackoverflow.com/questions/13150009/writing-characters-7f-127-as-hex-strings-according-to-code-page-1252-in-wind">Writing characters &gt; 7F (127) as hex strings according to code page 1252 in windows batch file</a></p>
  
  <p>I thought I could just replace the example hex values to 0xFF and 0xFE and make it echo to a file:</p>
  
  <pre><code>@echo off
  call :hex2Char 0xFF char_FF
  call :hex2Char 0xFE char_FE
  echo %char_FF% %char_800%
  exit /b
  
  :hex2Char  hexString  rtnVar
    for /f delims^=^ eol^= %%A in (
      'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%~1"'
    ) do set "%~2=%%A" &gt;&gt; temp.txt 
  exit /b
  </code></pre>
  
  <p>But it seems it was not to be as simple as that. Two issues that come out of it:
  1. It writes some unicode characters in there, but it's not the same as the unicode helper file, as hexdump shows.</p>
  
  <pre><code>file name: UniHeader.txt
  mime type: 
  
  0000-0003:  ef bb bf                                   
  
  
  file name: temp.txt
  mime type: 
  
  0000-0000:                                                   
  </code></pre>
  
  <p>in fact I can change the FF or FE and it still only prints 0000-0000 in the hexdump output...</p>
  
  <ol start="2">
  <li>I can add whatever I want after that file (like the code of writing my header-less file and appending it to the created one, the code stops at the second exit /b and does not write anything anymore. (But removing it makes the whole thing not work at all and moving it to the end of the file makes it unable to find the file being dropped onto the bat)
  In all honesty I am not getting through these few codeline at the moment. exit /b marks the end of the command, if I get it correctly, then, why does it continue to work after the first exit /b, but stops at the second exit /b? I also tries with labels and a goto, didn't work.</li>
  </ol>
  
  <p>I am at a loss right now. Is there any elegant way to solve this?</p>