1

I ended up in here

How can I get the list of files in a directory using C or C++?

I am afraid none of the codes support UTF-8. I modified Bad's code a bit to accept the UTF-8 directory.

//#define BOOST_FILESYSTEM_VERSION 3
#include <string>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>

using namespace std;
using namespace boost::filesystem;

int main()
{
    boost::filesystem::detail::utf8_codecvt_facet utf8;
    boost::filesystem::path p;
    p.assign(u8"C:\\", utf8);

    for (auto i = directory_iterator(p); i != directory_iterator(); i++)
    {
        if (!is_directory(i->path())) //we eliminate directories
        {
            cout << u8"Fil:" + i-> path().filename().string() << endl;
        }
        else
        {
            cout << u8"Dir:" + i-> path().filename().string() << endl;
        }
    }
}

But I don't know how to get the UTF-8 files output.

Community
  • 1
  • 1
Mark09
  • 263
  • 1
  • 4
  • 9
  • Just curious, why UTF8 file paths on MS Windows? – Richard Critten Mar 02 '17 at 00:18
  • 2
    Because it's the right thing to do. All character data should be UTF-8, all the time. – R.. GitHub STOP HELPING ICE Mar 02 '17 at 00:41
  • 1
    Because user do this. Like [http://i39.tinypic.com/zvtw2g.png](http://i39.tinypic.com/zvtw2g.png) from [https://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/use-meiryo-ui-instead-of-meiryo-for-japanese-text/5099a159-912f-48f4-b1de-01acf6f7c426](https://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/use-meiryo-ui-instead-of-meiryo-for-japanese-text/5099a159-912f-48f4-b1de-01acf6f7c426) – Mark09 Mar 02 '17 at 00:54
  • That's not C! Don't spam tags. – too honest for this site Mar 02 '17 at 01:07
  • Sorry for spamming the tag. Because I am still a newbie, I don't know how to use the correct tag so I just copied the original post tags, including tag c, plus the utf8. Except that I cannot think of anything. – Mark09 Mar 02 '17 at 03:53

0 Answers0