CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    31

    Change the search options.

    I have file which searches through different directories. The file code is hard coded to to return only mp3 files. I'm trying to edit it so that the user can select which file extensions such mp3 or txt ect.

    I tried using a check-box with no effect.


    Code:
    private void btnOpenFolder_Click(object sender, System.EventArgs e)
            {
                this.folderBrowserDialog.RootFolder = System.Environment.SpecialFolder.MyComputer;
                this.folderBrowserDialog.ShowNewFolderButton = false;
                DialogResult result = this.folderBrowserDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.clearListBox();
    
                    // retrieve the name of the selected folder
                    string foldername = this.folderBrowserDialog.SelectedPath;
    
                    // print the folder name on a label
                    this.textSearchPath.Text = foldername;
    
                    
    
                    foreach (string filename in Directory.GetFiles(foldername))
                    {
                        string FileTypeExtension = ".mp3";
                        string extension = Path.GetExtension(filename);
    
                        if (extension == FileTypeExtension)
                        {
                            this.listBox1.Items.Add(filename);
                        }
                    }
                }
    
                
            }
    
    
            private void clearListBox()
            {
                this.listBox1.Items.Clear();
            }
    
            private void Close_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                string FileTypeExtension = ".txt";
            }
    
            private void MP3File_CheckedChanged(object sender, EventArgs e)
            {
                string FileTypeExtension = ".mp3";
            }
    
            private void Clear_Click(object sender, EventArgs e)
            {
                this.listBox1.Items.Clear();
            }
    
            private void ShowFiles_Click(object sender, EventArgs e)
            {
               
            }
    
    
        }
    }

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Change the search options.

    So the User gets to choose 2 things..

    1) The Folder
    2) The Extension

    And then you want to get a list of all of the files in the folder (1) with the extension (2).

    Can you confirm?
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    Re: Change the search options.

    Looks to me like you need to make FileTypeExtension global to the class (only declare it once).

  4. #4
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Change the search options.

    yes.. Energ1ser is right. string FileTypeExtension needs to be declared only once outside the class and FileTypeExtension to be used where ever it is required.

  5. #5
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Change the search options.

    He is right, although I think the compiler would generate the same code in this case... but then...
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured