Solved

Counting files with a given extension??

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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