Solved

Find out which files are in a directory

Posted on 2000-05-09
4
170 Views
Last Modified: 2010-04-02
Hi,

King Of Stupid Questions speaking here... lol :)
How can I find out how many and which files are in a directory? In QBasic I always used to do a "SHELL "dir /s >> somefile.tmp"" And then open that file and loop through it, but that can never be a good method :) I hope there's some kind of function or something for it, so that I don't have to use one of my strange workarounds again :) (another would be having a hidden listbox on my dialog and filling that with a directory's contents, forgot the function for it but I did that before) :)

Thanks in advance
0
Comment
Question by:mgdPaul
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 30 total points
ID: 2795394
Check the FindFirstFile() and FindNextFile()...


Regards
Eirnava...
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2795395
WIN32_FIND_DATA w32fd;
HANDLE hFind;
UINT count=0;
hFind = FindFirstFile ( "c:\\*.*", &w32fd);

if ( INVALID_HANDLE_VALUE == hFind)
{
 // error
}
count++;


while( FindNextFile ( hFind, &w32fd))
{
count++;
//note,. and .. are also files.The other info,like file name, are contained in the w32fd,check it...
}

if( ERROR_NO_MORE_FILES != GetLastError()))
{
 // error
}
FindClose ( hFind);

Regards
Eirnava...
0
 

Author Comment

by:mgdPaul
ID: 2795406
Thanks a lot! :) I remember Visual Basic having a function Dir() I believe... never quite learned to work with that, and now that I finally really need to know about the files in a directory in C(++) I can't seem to find out how.... but thanks to you I can continue my project now :)
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2795452
You are welcome...
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.

743 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

10 Experts available now in Live!

Get 1:1 Help Now