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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operator '|' cannot be applied to operands of type 'string' and 'stri 1

Status
Not open for further replies.

Programming2007

Programmer
Nov 10, 2006
24
US
I want to say search for either string *.htm and *.aspx. But the parameter needs to be a string not a boolean expression which is (*.htm && *.aspx). I get the error message ... Operator '|' cannot be applied to operands of type 'string' and 'string'. How do I allow my string parameter to be a boolean expression evaluating which string should be the parameter???

strFileTypes = ("*.htm" && "*.aspx")

string [] s = Directory.GetFiles("C:\\SCoutline4\\",(strFileTypes));
leads to error Operator '|' cannot be applied to operands of type 'string' and 'string'.
strFileTypes = ("*.htm" && "*.aspx")

string [] s = Directory.GetFiles("C:\\SCoutline4\\",("*.htm"));
works for all htm files
strFileTypes = ("*.htm" && "*.aspx")

string [] s = Directory.GetFiles("C:\\SCoutline4\\",("*.aspx));
works for all aspx files
 
strFileTypes = ("*.htm" && "*.aspx")

What is this line?

This is a filter? Should be something like:

strFileTypes = "*.htm && *.aspx";

Otherwise you're assigning 2 strings to 1 string variable which you can't do.
 
Unfortunately that doesn't work it searches for files of type "*.htm && *.css", with the and in the middle.
 
As far as I am aware the SearchPattern parameter of GetFiles() is only used for searches such as "*.md?" to look for Access databases (.mdb, .mde) or SQL Server databases (.mdf) - and not as you are attempting as an extension filter as you would see in the FileOpen dialog box.


Hope this helps.

[vampire][bat]
 
From what I can tell, the GetFiles method will only accept one search criteria at a time.

What you can do is perform two searchs, and combine the results using the CopyTo method on the 1st result.
Code:
string[] first = Directory.GetFiles("*.htm");
string[] second = Directory.GetFiles("*.aspx");
second.CopyTo(first, 0);

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top