Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Suppose in a directory I have few .xml file. Some of these file has "_schema" string in it's name.I want to get those file name that doesn't contain this particular string.
C#
Directory.GetFiles(pathOfTable,".xml")

This code return all .xml file name
C#
Directory.GetFiles(pathOfTable,"_schema.xml")

this code return all file name with "_schema" string
But, I need those file name that does not contain this string
Posted
Updated 22-Sep-13 7:30am
v2

Directory.GetFiles does not contain a NOT option.
The way to go about it is to get all files in folder, then "query" each of them with a string operation
C#
string[] fileEntries = Directory.GetFiles(targetDirectory);

foreach(string fileName in fileEntries)
{

     if (!fileName.EndsWith("_schema.xml"))
          actions...

}

That way, if the file name does not contain such string, the "if" statement will kick in.
 
Share this answer
 
v5
as c# view :
return all file and use list processing algorithms or simply use linq to any post processing
XML
string[] fa = { "test_schemaoky", "farshad", "_schemafarshad", "saeidi" };
            List<string> fl = new List<string>();
            fl.AddRange(fa);
            List<string> f2=fl.FindAll(itm => itm.IndexOf("_schema")==-1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900