Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello

How can I find out how many files have the extension ".exe" in the current directory? Does a function exist to do this?

Thanks
 
Check out the MFC class CFile, it has such methods as...Create Creates a new file
Open Opens an existing file.
Close Closes the file.
Read Reads a number of bytes from the file.
Write Writes a number of bytes to the file.
Seek Sets the file position.
GetPosition Returns the current file position.
Flush Flushes all uncommitted data to the file.
GetSize Returns the size of the file.
GetFileTime Returns the file creation-, modification- and access-times.
FileExists Returns whether a filename exists.
Delete Deletes a file.
Rename Renames a file.

FileExists could be a good one, and I believe you can use wildcards such as *.exe. Then just run through a loop and use a counter

 
Also there is another useful method called findfile

Here's a sample bit of code to get you started

CFile finder;

bool files = finder.FindFile("*.exe");

while (files)
{


files = finder.FindNextFile();
filename = finder.GetFileName();
 
With the finder, you also have to check if it is a directory. You will get "." and ".." when searching (at least that has been my experience.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top