Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find out which files are in a directory

Posted on 2000-05-09
4
Medium Priority
?
180 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 120 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

670 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