Solved

Counting files with a given extension??

Posted on 2004-09-25
1
340 Views
Last Modified: 2010-04-24
I am needing to count the files inside a certain directory with a certain filemask (eg: "*.ini")when a given event occurs.  I do not need a recursive search through sub directories

I know I can load each into an array and count them there.  I am wondering if there is a directory* or file* class in c++ .net that would be quicker to execute and code??

Thanks, Jason
0
Comment
Question by:jdhatch
1 Comment
 
LVL 19

Accepted Solution

by:
drichards earned 500 total points
ID: 12153365
If you are using managed C++, there is a Directory class that has a static method called GetFiles:

    System::String *files[] =  System::IO::Directory::GetFiles(S"C:\", S"*.ini");
    int count = files->Length;
    System::Console::WriteLine(files[0]); // Access the array to get file names.

If you are not using managed C++, you can use CFileFind if you are using MFC or FindFirstFile/FindNextFile (which are how CFileFind is implemented) if you don't want to use MFC.  Are you using managed code?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

26 Experts available now in Live!

Get 1:1 Help Now