Solved

Find out which files are in a directory

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 181
Load and store *.pnm image file 1 86
returning a dereferenced pts in C++ 10 149
thread-safe code in c++ 2 102
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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall‚Ķ
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

778 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