Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:49:13+00:00 2026-05-29T20:49:13+00:00

I got this source code from somewhere on the Net. It searches for files

  • 0

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:

#include <string>
#include <vector>
#include <iostream>

#include <windows.h>
#include <conio.h>



int SearchDirectory(std::vector<std::string> &refvecFiles,
                    const std::string        &refcstrRootDirectory,
                    const std::string        &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(), &FileInformation);
  if(hFile != INVALID_HANDLE_VALUE)
  {
    do
    {
      if(FileInformation.cFileName[0] != '.')
      {
        strFilePath.erase();
        strFilePath = refcstrRootDirectory + "\\" + FileInformation.cFileName;

        if(FileInformation.dwFileAttributes & 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, &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<std::string> vecAviFiles;
  std::vector<std::string> vecTxtFiles;


  // Search 'c:' for '.avi' files including subdirectories
  iRC = SearchDirectory(vecAviFiles, "d:", "doc");
  if(iRC)
  {
    std::cout << "Error " << iRC << std::endl;
    return -1;
  }

  // Print results
  for(std::vector<std::string>::iterator iterAvi = vecAviFiles.begin();
      iterAvi != vecAviFiles.end();
      ++iterAvi)
    std::cout << *iterAvi << std::endl;

  // Search 'c:\textfiles' for '.txt' files excluding subdirectories
  /*
  iRC = SearchDirectory(vecTxtFiles, "c:\\textfiles", "txt", false);
  if(iRC)
  {
    std::cout << "Error " << iRC << std::endl;
    return -1;
  }

  // Print results
  for(std::vector<std::string>::iterator iterTxt = vecTxtFiles.begin();
      iterTxt != vecTxtFiles.end();
      ++iterTxt)
    std::cout << *iterTxt << std::endl;

  // Wait for keystroke
  _getch();
  */

  return 0;
}

The problem is that when it finds a filename with Arabic text, it doesn’t display it correctly; It just shows "?????????????????????". I need the file path to send to a server. Is there anyway to solve the problem?

UPDATE:
I have revised the code.

The new code is as follows:

#include <boost/filesystem.hpp>
namespace bf = boost::filesystem;
#include <string>
#include <iostream>
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 << e_string;
    }
     if (!bf::exists(fileCopiedDestination))
        {
        cerr << e_string;
    }
    try
    {
        bf::copy_file(fileCopied,fileCopiedDestination);
    }
    catch(std::exception e)
    {
        cout << e.what();
    }
}

This code compiles, but I get this error:

ErrorErrorstd::exception

Also, the copying process fails.

I tried to change this line:
string fileName = "C:\\حم.txt";

to:
string fileName = "C:\\??.txt";

but in vain.

How can I copy this file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:49:16+00:00Added an answer on May 29, 2026 at 8:49 pm

    You’re “just a beginner”, so I strongly suggest this: download Boost and use Boost.Filesystem. It has a class boost::filesystem::path that represents a filename. It’s all you should use for dealing with filenames. Use the Boost.Filesystem functions for searching for files, and use the boost::filesystem::path object and the special iostreams in Boost.Filesystem to open those files.

    Printing Unicode-encoded strings to the console window is… not easily done in Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this source code where I got it from net tutsplus. I have
I got this code for a parser from this link. http://www.warriorpoint.com/blog/2009/07/19/android-simplified-source-code-for-parsing-and-working-with-xml-data-and-web-services-in-android/ I am getting
I am rather new to VIM. I got some source code and this is
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I just got a source code file from a friend. The file was created
I got Calculator source code from google's android.git.kernel.org and successfully build the project without
Ive got this code from an ebook tutorial on embedding MPMoviePlayerController from a VIEW
when i search for open source for domain checker, i got this reference http://www.codeproject.com/KB/aspnet/DataScraping.aspx
I got the image like this (it's a graph): (source: kitconet.com ) I want
Got this line of code here but its not working. private void Button_Click(object sender,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.