[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Multiple File Extensions With FindFirstFile

Posted on 1998-10-30
3
Medium Priority
?
2,083 Views
Last Modified: 2013-12-03
I am using FindFirstFile() and FindNextFile() to search a directory for files.  I have now found that I need to search for more than one extension so is this possible from one FindFirstFile() or will I have to trawl through the directory twice ?  (I don't want to use *.* but will if I have to)
0
Comment
Question by:ssherlock
[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 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1415702
I'm using *.* is such cases. Though, try using "*.doc;*.txt". Perhaps it works...

Regards, Madshi.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 400 total points
ID: 1415703
I can give you an answer but that is not the answer you want to  here. It is not possible to do it using FindFirstFile or FindFirstFileEx.

A function that might help you is PathMatchSpec. An exported function of the shell. Here is the documentation.

PathMatchSpec




BOOL PathMatchSpec(
    LPCTSTR pszFileParam,
    LPCTSTR pszSpec
    );



Searches a string using a DOS wild card match type. The string can be searched for a particular file extension, such as *.bmp, *.doc, and so on.

•Returns TRUE if the string matches, or FALSE otherwise.


pszFileParam

Address of the string to be searched.

pszSpec

Address of the file type for which to search.



Example:

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
      // String path name 1.
      char buffer_1[] = "C:\\Test\\File.txt";
      char *lpStr1;
      lpStr1 = buffer_1;

      // String path name 2.
      char buffer_2[] = "C:\\Test\\File.bmp";
      char *lpStr2;
      lpStr2 = buffer_2;

      // String path name 3.
      char buffer_3[] = "*.txt";
      char *lpStr3;
      lpStr3 = buffer_3;

      // String path name 4.
      char buffer_4[] = "C:\\Test\\File";
      char *lpStr4;
      lpStr4 = buffer_4;


      // Variable to get the return.
      // from "PathMatchSpec"      
    int      retval;      

      // Test path name 1.
    retval = PathMatchSpec(lpStr1,lpStr3);
    cout << "The contents of String 1: " << lpStr1
             << "\nThe return value from the function is " << retval << " = TRUE" << endl;

      // Test path name 2.
      retval = PathMatchSpec(lpStr2,"*.bmp");
    cout << "The contents of String 2: " << lpStr2
             << "\nThe return value from the function is " << retval << " = TRUE" << endl;

      // Test path name 4.
      retval = PathMatchSpec(lpStr4,lpStr2);
    cout << "The contents of String 4: " << lpStr4
             << "\nThe return value from the function is " << retval << " = FALSE"<< endl;
}
OUTPUT:
==========
The contents of String 1: C:\Test\File.txt
The return value from the function is 1 = TRUE
The contents of String 2: C:\Test\File.bmp
The return value from the function is 1 = TRUE
The contents of String 4: C:\Test\File
The return value from the function is 0 = FALSE

0
 

Author Comment

by:ssherlock
ID: 1415704
Thanks but that wasn't really acceptable for this project (I will keep it handy though).  I eneded up putting everything into a function and calling it twice, feeding in the extension to search for each time.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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