Advertisement

07.16.2008 at 04:27PM PDT, ID: 23571663
[x]
Attachment Details

Searching through a loop of filenames and looking for a particular file extension type.

Asked by stephenlecomptejr in C# Programming Language

I have the following code and I'm trying to make sure it adds only to a listbox if it finds the .PLT file extension.  For some reason its still adding all the files it finds.  I would also like to change whats below to account for more than one file type extensions.  For example, I may want to check for .PDF and .doc files that are in a collection.  Instead of running the collection and then doing the file search what is the best method to keep the searching from only performing once?

foreach (string fileName in fileEntries)
            {
                // do something with fileName
   
                Directions = Path.GetFileName(fileName);

                Console.WriteLine(Directions.LastIndexOf(".plt"));

                if (Directions.LastIndexOf(".plt") !=0 || Directions.LastIndexOf(".PLT") !=0)
                {
                    //theName = Path.GetFileName((fileName));
                    //theName = (fileName);
                    lstFrom.Items.Add(Directions);
                }
             
            }Start Free Trial
[+][-]07.16.2008 at 05:29PM PDT, ID: 22021436

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Sign Up Now!
Solution Provided By: jaime_olivares
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.16.2008 at 11:04PM PDT, ID: 22022653

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.21.2008 at 11:54AM PDT, ID: 22053301

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.26.2008 at 12:14PM PDT, ID: 22095905

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628