Solved

Find out which files are in a directory

Posted on 2000-05-09
4
177 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

Industry Leaders: 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!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

740 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