Solved

Getting file and directory names in a directory.

Posted on 2003-11-11
3
403 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

25 Experts available now in Live!

Get 1:1 Help Now