Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

Getting file and directory names in a directory.

hi;
i want to get the directory and file names in a directory. And adding them into a pop-up menu
i want to create a start-up menu like windows'. thanks for your help.
0
kenanerdey
Asked:
kenanerdey
  • 2
1 Solution
 
AlexFMCommented:
See FindFirstFile, FindNextFile, FindClose.
0
 
kenanerdeyAuthor Commented:
i now but, how will i know what i found is file or directory ? how will i construct the loop ?
0
 
AlexFMCommented:
   WIN32_FIND_DATA find_data;
    CString sSearchString = _T("C:\\SomeDirectory\\*.*");  // set here your search string
   
    HANDLE hFindFileHandle = FindFirstFile(
        sSearchString,
        &find_data);
   
   
    if ( hFindFileHandle == INVALID_HANDLE_VALUE )
    {
        return;
    }
   
    while ( TRUE )
    {
        if ( ! (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )   // not directory
        {
            // Handle file here. It's name (without path) is in find_data.cFileName
        }
       
        // next file
        if ( ! FindNextFile(hFindFileHandle, &find_data) )
            break;
    }
   
    FindClose(hFindFileHandle);
   
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now