Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,


i want to extract only .c,.c++,.asm,.h files from a folder . if i use following code it is extracting all types of files.


C#
foreach (String f in Directory.GetFiles(rootdir,"*.cpp"))
                {
                    Main.Nodes.Add(f);
                }



by using above code i am able extract only cpp files but i want to extract .c,.c++,.asm,.h files and add to treeview.
Posted

Hi,

Check this link

thanks
-Amit
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Feb-12 0:20am    
This thread really shows a resolution of the problem related to "simple" use of GetFiles. My 5.

I explain it in detail with my other answer. Please see my answer.
--SA
AmitGajjar 9-Feb-12 0:22am    
Thanks SA
The method GetFiles has a serious flaw with interpretation of a file mask.

This problem is explained and resolved here: Directory.Get.Files search pattern problem[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 9-Feb-12 10:20am    
5'ed!
Sergey Alexandrovich Kryukov 9-Feb-12 12:06pm    
Thank you, Espen.
--SA
Hi,

try to check following link:
http://www.dreamincode.net/code/snippet2823.htm[^]

Regards
Robert
 
Share this answer
 
Hi,

See this sample code if could help:
// Filter template extention
private string[] AcceptedFileTypes = new string[]
{
"c","c++","jpe","asm","h"
};

string FileErrorMessage = "";
string ValidationString = ".*(";
int i = 0;
while (i < AcceptedFileTypes.Length)
{
ValidationString += "[\\." + AcceptedFileTypes[i] + "]";
if (i < (AcceptedFileTypes.Length - 1))
{
ValidationString += "|";
}
FileErrorMessage += AcceptedFileTypes[i];
if (i < (AcceptedFileTypes.Length - 1))
{
FileErrorMessage += ", ";
}
i += 1;
}
FileValidator.ValidationExpression = ValidationString + ")$";
FileValidator.ErrorMessage = FileErrorMessage;

 
Share this answer
 
v3

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