title: LUA: how to correctly read UFT8 file names and path with accented letters and umlaut?
body: <p>Inside a more complex script in LUA, I created the following function, that is supposed to
  retrieve the list of all audio files located into a directory, which is specified when the function is called (first parameter).</p>
  <p>The function returns a formatted HTML line or a CSV one, based on the value of the 2nd parameter.</p>
  <p>If 1, it returns HTML
  If 2, it returns CSV</p>
  <p>This function works fine unless path and/or file names don't have accented letters or umlauts.
  Then fails.</p>
  <p>here an exaggerated example, with which I've made tests:</p>
  <pre><code>J:\PRODUCTION\tüv-ààéérï-utf8\Rendering\tüv-ààéérï-utf8_.wav
  </code></pre>
  <p>I did try to implement solution like the one presented here:</p>
  <p><a href="https://stackoverflow.com/questions/41855842/converting-utf-8-string-to-ascii-in-pure-lua/41859181#comment124002321_41859181">converting UTF-8 string to ASCII in pure LUA</a></p>
  <p>and here:</p>
  <p><a href="https://stackoverflow.com/questions/36717078/handle-special-characters-in-lua-file-path-umlauts">Handle special characters in lua file path (umlauts)</a></p>
  <p>but unsuccessfully.</p>
  <p>Is there a way, in LUA, to get file names and path as they have accented/umlauted characters?</p>
  <p><strong>IMPORTANT:</strong>
  the LUA interpreter is not standalone. It's the one built-in the audio application Reaper.
  Hence, I can't install some particular LUA extension apart.
  So, I need to write some code but I'm totally lost.
  [EDIT]
  operating system Windows, but i should work also on Mac and Linux as well</p>
  <pre><code>----------------------------------------------
  -- SCAN RENDERED AUDIO
  ----------------------------------------------
  function scandir(directory,format)
    local i, t, popen = 0, {}, io.popen
    t = ''
    local f=io.popen('dir '..directory)
      for filename in popen('dir &quot;'..directory..'&quot; /b'):lines() do
        local extension = filename:match(&quot;^.+(%..+)$&quot;)
        if extension == &quot;.wav&quot; or
           extension == &quot;.mp3&quot; or
           extension == &quot;.flac&quot; or
           extension == &quot;.mov&quot; or
           extension == &quot;.ogg&quot; or
           extension == &quot;.mp4&quot; then
            uriFormat = filename:gsub(&quot; &quot;, &quot;%%20&quot;)
            if format == 1 then
              t = t..'&lt;tr class=&quot;Rendered&quot;&gt;&lt;td&gt;'..directory..'&lt;/td&gt;&lt;td&gt;'..tostring(filename)..'&lt;/td&gt;&lt;td&gt;&lt;audio controls src=&quot;'..directory..'/'..tostring(uriFormat)..'&quot;/&gt;&lt;/td&gt;&lt;/tr&gt;'
            elseif format == 2 then
              t = t..directory..','..tostring(filename)..','..directory..tostring(filename)..LF
            end
            i = i + 1
        end
   
      end
    return t
  end
  </code></pre>