title: How can I handle filenames with Arabic text in Windows?
body: <p>I got this source code from somewhere on the Net.  It searches for files on the hard disk and prints out the path of the files:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  #include &lt;windows.h&gt;
  #include &lt;conio.h&gt;
  
  
  
  int SearchDirectory(std::vector&lt;std::string&gt; &amp;refvecFiles,
                      const std::string        &amp;refcstrRootDirectory,
                      const std::string        &amp;refcstrExtension,
                      bool                     bSearchSubdirectories = true)
  {
    std::string     strFilePath;             // Filepath
    std::string     strPattern;              // Pattern
    std::string     strExtension;            // Extension
    HANDLE          hFile;                   // Handle to file
    WIN32_FIND_DATA FileInformation;         // File information
  
  
    strPattern = refcstrRootDirectory + "\\*.*";
  
    hFile = ::FindFirstFile(strPattern.c_str(), &amp;FileInformation);
    if(hFile != INVALID_HANDLE_VALUE)
    {
      do
      {
        if(FileInformation.cFileName[0] != '.')
        {
          strFilePath.erase();
          strFilePath = refcstrRootDirectory + "\\" + FileInformation.cFileName;
  
          if(FileInformation.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)
          {
            if(bSearchSubdirectories)
            {
              // Search subdirectory
              int iRC = SearchDirectory(refvecFiles,
                                        strFilePath,
                                        refcstrExtension,
                                        bSearchSubdirectories);
              if(iRC)
                return iRC;
            }
          }
          else
          {
            // Check extension
            strExtension = FileInformation.cFileName;
            strExtension = strExtension.substr(strExtension.rfind(".") + 1);
  
            if(strExtension == refcstrExtension)
            {
              // Save filename
              refvecFiles.push_back(strFilePath);
            }
          }
        }
      } while(::FindNextFile(hFile, &amp;FileInformation) == TRUE);
  
      // Close handle
      ::FindClose(hFile);
  
      DWORD dwError = ::GetLastError();
      if(dwError != ERROR_NO_MORE_FILES)
        return dwError;
    }
  
    return 0;
  }
  
  
  int main()
  {
    int                      iRC         = 0;
    std::vector&lt;std::string&gt; vecAviFiles;
    std::vector&lt;std::string&gt; vecTxtFiles;
  
  
    // Search 'c:' for '.avi' files including subdirectories
    iRC = SearchDirectory(vecAviFiles, "d:", "doc");
    if(iRC)
    {
      std::cout &lt;&lt; "Error " &lt;&lt; iRC &lt;&lt; std::endl;
      return -1;
    }
  
    // Print results
    for(std::vector&lt;std::string&gt;::iterator iterAvi = vecAviFiles.begin();
        iterAvi != vecAviFiles.end();
        ++iterAvi)
      std::cout &lt;&lt; *iterAvi &lt;&lt; std::endl;
  
    // Search 'c:\textfiles' for '.txt' files excluding subdirectories
    /*
    iRC = SearchDirectory(vecTxtFiles, "c:\\textfiles", "txt", false);
    if(iRC)
    {
      std::cout &lt;&lt; "Error " &lt;&lt; iRC &lt;&lt; std::endl;
      return -1;
    }
  
    // Print results
    for(std::vector&lt;std::string&gt;::iterator iterTxt = vecTxtFiles.begin();
        iterTxt != vecTxtFiles.end();
        ++iterTxt)
      std::cout &lt;&lt; *iterTxt &lt;&lt; std::endl;
  
    // Wait for keystroke
    _getch();
    */
  
    return 0;
  }
  </code></pre>
  
  <p>The problem is that when it finds a filename with Arabic text, it doesn't display it correctly; It just shows <code>"?????????????????????"</code>.  I need the file path to send to a server.  Is there anyway to solve the problem?</p>
  
  <p><strong>UPDATE:</strong>
  I have revised the code.</p>
  
  <p>The new code is as follows:</p>
  
  <pre><code>#include &lt;boost/filesystem.hpp&gt;
  namespace bf = boost::filesystem;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  string e_string = "Error";
  int main()
  {
      string fileName = "C:\\حم.txt";
      string destination = "D:\\log.txt" ;
      bf::path fileCopied(fileName);
      bf::path fileCopiedDestination (destination);
      if (!bf::exists(fileCopied) )
      {
          cerr &lt;&lt; e_string;
      }
       if (!bf::exists(fileCopiedDestination))
          {
          cerr &lt;&lt; e_string;
      }
      try
      {
          bf::copy_file(fileCopied,fileCopiedDestination);
      }
      catch(std::exception e)
      {
          cout &lt;&lt; e.what();
      }
  }
  </code></pre>
  
  <p>This code compiles, but I get this error:</p>
  
  <pre><code>ErrorErrorstd::exception
  </code></pre>
  
  <p>Also, the copying process fails.</p>
  
  <p>I tried to change this line:<br>
  <code>string fileName = "C:\\حم.txt";</code>  </p>
  
  <p>to:<br>
  <code>string fileName = "C:\\??.txt";</code> </p>
  
  <p>but in vain.  </p>
  
  <p>How can I copy this file?</p>