Solved

Counting files with a given extension??

Posted on 2004-09-25
1
376 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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