Solved

Getting file and directory names in a directory.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TTimer no longer functioning 7 90
Grammars for C C++ and java 1 122
C++ mouse_event mouse look 7 82
c++, dynamic object by json 1 41
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

786 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