Solved

Getting file and directory names in a directory.

Posted on 2003-11-11
3
418 Views
Last Modified: 2010-04-01
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
Comment
Question by:kenanerdey
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9720904
See FindFirstFile, FindNextFile, FindClose.
0
 

Author Comment

by:kenanerdey
ID: 9721606
i now but, how will i know what i found is file or directory ? how will i construct the loop ?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 9721703
   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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now