Author Topic: VC++ - Enumerating list of files in a folder  (Read 1357 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
VC++ - Enumerating list of files in a folder
« on: December 01, 2011, 07:01:39 pm »
Here is the code to enumerate the list of files in a directory in VC++. It uses FindFirstFile and FindNextFile functions along with WIN32_FIND_DATA struct.

Code:
//Source Code Listing

// searchkey can be = "c:\\kathir\\*.txt";
int GetFileList(const char *searchkey, std::vector<std::string> &list)
{
    WIN32_FIND_DATA fd;
    HANDLE h = FindFirstFile(searchkey,&fd);

    if(h == INVALID_HANDLE_VALUE)
    {
        return 0; // no files found
    }

    while(1)
    {
        list.push_back(fd.cFileName);
        if(FindNextFile(h, &fd) == FALSE)
            break;
    }
    return list.size();
}

ClintonEnupt

  • Hero Member
  • *****
  • Posts: 542
    • Препарат Alergyx от аллергии
Фабрика Инте
« Reply #1 on: April 08, 2017, 04:04:12 am »
Гостиная Версаль
www.imp-mebeli.ru
----------

ClintonEnupt

  • Hero Member
  • *****
  • Posts: 542
    • Препарат Alergyx от аллергии
Фабрика Инте
« Reply #2 on: April 08, 2017, 11:11:15 pm »
Гостиная Версаль
www.imp-mebeli.ru
----------

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1