Solved

Find out which files are in a directory

Posted on 2000-05-09
4
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 126
Move constructor only called if marked noexcept? 6 123
C++ help/ Toy problem 19 71
Can Live bindings change TGrid Cell Colour ? 1 64
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 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.

752 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