Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SearchDirectory

SearchDirectory

Scheduled Pinned Locked Moved C#
csharplinqgraphicsalgorithms
20 Posts 5 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HubSnippets
    wrote on last edited by
    #1

    The Microsoft Windows search "textbox" on the top-right corner of the Window Explorer is not too efficient when searching for files. So, I thought I should write something that would provide an easily way of searching for files in your Windows directories. There is a small application written to do a quick and smart search of files in a directory. It's still under development and your comments and contributions would be appreciated.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Data.OleDb;
    using System.Data.SqlClient;

    namespace WindowsFormsApplication3
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

        private void btnBrowse\_Click(object sender, EventArgs e)
        {
            // Specify a Directory name or path into the File Directory TextBox
            FolderBrowserDialog openDir = new FolderBrowserDialog();
    
            //Choose a Directory path name and display on the File Direcotry TextBox
            if (openDir.ShowDialog() == DialogResult.OK)
                txtBxDir.Text = openDir.SelectedPath;
    
            else
                MessageBox.Show("Make sure you have selected a valid path name");
        }
    
        public void searchDirectory()
        {
    
            //Check for valid File Type and File Directory
            if (cmbBx.Text == "") MessageBox.Show("Input a valid file type format");
            else if (txtBxDir.Text == "") MessageBox.Show("Input a valid directory pathname");
    
            try
            {
                //Search the specified Directory for files of a particular file type
                String\[\] arrayFileList = Directory.GetFiles(txtBxDir.Text, cmbBx.Text, SearchOption.AllDirectories);
                foreach (string file in arrayFileList)
                {
                    string fileName = file.Substring(file.LastIndexOf("\\\\") + 1);
                    txtBxResult.Text += fileName + "\\r\\n";
                }
    
            }
            catch (IOException)
            {
                MessageBox.Show("Choose the correct file type");
            }
        }
    
        private string getTextBoxNoFiles()
        {
            string noFiles = txtBxResult.Lines.Length.ToString();
            return txtBxNoFiles.Text = noFiles;
        }
    
    L J B 3 Replies Last reply
    0
    • H HubSnippets

      The Microsoft Windows search "textbox" on the top-right corner of the Window Explorer is not too efficient when searching for files. So, I thought I should write something that would provide an easily way of searching for files in your Windows directories. There is a small application written to do a quick and smart search of files in a directory. It's still under development and your comments and contributions would be appreciated.

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.IO;
      using System.Data.OleDb;
      using System.Data.SqlClient;

      namespace WindowsFormsApplication3
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

          private void btnBrowse\_Click(object sender, EventArgs e)
          {
              // Specify a Directory name or path into the File Directory TextBox
              FolderBrowserDialog openDir = new FolderBrowserDialog();
      
              //Choose a Directory path name and display on the File Direcotry TextBox
              if (openDir.ShowDialog() == DialogResult.OK)
                  txtBxDir.Text = openDir.SelectedPath;
      
              else
                  MessageBox.Show("Make sure you have selected a valid path name");
          }
      
          public void searchDirectory()
          {
      
              //Check for valid File Type and File Directory
              if (cmbBx.Text == "") MessageBox.Show("Input a valid file type format");
              else if (txtBxDir.Text == "") MessageBox.Show("Input a valid directory pathname");
      
              try
              {
                  //Search the specified Directory for files of a particular file type
                  String\[\] arrayFileList = Directory.GetFiles(txtBxDir.Text, cmbBx.Text, SearchOption.AllDirectories);
                  foreach (string file in arrayFileList)
                  {
                      string fileName = file.Substring(file.LastIndexOf("\\\\") + 1);
                      txtBxResult.Text += fileName + "\\r\\n";
                  }
      
              }
              catch (IOException)
              {
                  MessageBox.Show("Choose the correct file type");
              }
          }
      
          private string getTextBoxNoFiles()
          {
              string noFiles = txtBxResult.Lines.Length.ToString();
              return txtBxNoFiles.Text = noFiles;
          }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      If you have a question then please edit the above and add it to your post. If this is your suggested improvement for Windows Explorer, then write an article or Tip and post it in the article submission section[^].

      Use the best guess

      J 1 Reply Last reply
      0
      • L Lost User

        If you have a question then please edit the above and add it to your post. If this is your suggested improvement for Windows Explorer, then write an article or Tip and post it in the article submission section[^].

        Use the best guess

        J Offline
        J Offline
        Jasmine2501
        wrote on last edited by
        #3

        This is C# *discussions* so I think it's ok if he doesn't have a question and is just looking for general advice. Right? Probably not gonna get it, but I think it's a valid post for this section, and shouldn't the "questions" really be going to the quick answers section or on Stack Overflow? This is the kind of thing I'd love to see here, or anywhere really... code discussions and critique is much more fun than answering dumb questions.

        L 1 Reply Last reply
        0
        • H HubSnippets

          The Microsoft Windows search "textbox" on the top-right corner of the Window Explorer is not too efficient when searching for files. So, I thought I should write something that would provide an easily way of searching for files in your Windows directories. There is a small application written to do a quick and smart search of files in a directory. It's still under development and your comments and contributions would be appreciated.

          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.Data;
          using System.Drawing;
          using System.Linq;
          using System.Text;
          using System.Windows.Forms;
          using System.IO;
          using System.Data.OleDb;
          using System.Data.SqlClient;

          namespace WindowsFormsApplication3
          {
          public partial class Form1 : Form
          {
          public Form1()
          {
          InitializeComponent();
          }

              private void btnBrowse\_Click(object sender, EventArgs e)
              {
                  // Specify a Directory name or path into the File Directory TextBox
                  FolderBrowserDialog openDir = new FolderBrowserDialog();
          
                  //Choose a Directory path name and display on the File Direcotry TextBox
                  if (openDir.ShowDialog() == DialogResult.OK)
                      txtBxDir.Text = openDir.SelectedPath;
          
                  else
                      MessageBox.Show("Make sure you have selected a valid path name");
              }
          
              public void searchDirectory()
              {
          
                  //Check for valid File Type and File Directory
                  if (cmbBx.Text == "") MessageBox.Show("Input a valid file type format");
                  else if (txtBxDir.Text == "") MessageBox.Show("Input a valid directory pathname");
          
                  try
                  {
                      //Search the specified Directory for files of a particular file type
                      String\[\] arrayFileList = Directory.GetFiles(txtBxDir.Text, cmbBx.Text, SearchOption.AllDirectories);
                      foreach (string file in arrayFileList)
                      {
                          string fileName = file.Substring(file.LastIndexOf("\\\\") + 1);
                          txtBxResult.Text += fileName + "\\r\\n";
                      }
          
                  }
                  catch (IOException)
                  {
                      MessageBox.Show("Choose the correct file type");
                  }
              }
          
              private string getTextBoxNoFiles()
              {
                  string noFiles = txtBxResult.Lines.Length.ToString();
                  return txtBxNoFiles.Text = noFiles;
              }
          
          J Offline
          J Offline
          Jasmine2501
          wrote on last edited by
          #4

          What is wrong with the built in search, and how will this be better??? I think when the app starts up, don't make the user 'select' a folder, just show a treeview of their hard drive automatically. I think you need to create some classes to separate the interface logic from the searching (and this will allow multi-threading the interface later), but that discussion is not relevant without the answer to the first question.

          H 1 Reply Last reply
          0
          • J Jasmine2501

            This is C# *discussions* so I think it's ok if he doesn't have a question and is just looking for general advice. Right? Probably not gonna get it, but I think it's a valid post for this section, and shouldn't the "questions" really be going to the quick answers section or on Stack Overflow? This is the kind of thing I'd love to see here, or anywhere really... code discussions and critique is much more fun than answering dumb questions.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Jasmine2501 wrote:

            This is C# *discussions* so I think it's ok if he doesn't have a question

            Not according to http://www.codeproject.com/Messages/1278604/How-to-get-an-answer-to-your-question.aspx[^].

            Jasmine2501 wrote:

            and shouldn't the "questions" really be going to the quick answers section or on Stack Overflow?

            No.

            Jasmine2501 wrote:

            This is the kind of thing I'd love to see here, or anywhere really... code discussions and critique is much more fun than answering dumb questions.

            Then I suspect you are at the wrong place.

            Use the best guess

            J 1 Reply Last reply
            0
            • H HubSnippets

              The Microsoft Windows search "textbox" on the top-right corner of the Window Explorer is not too efficient when searching for files. So, I thought I should write something that would provide an easily way of searching for files in your Windows directories. There is a small application written to do a quick and smart search of files in a directory. It's still under development and your comments and contributions would be appreciated.

              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.Data;
              using System.Drawing;
              using System.Linq;
              using System.Text;
              using System.Windows.Forms;
              using System.IO;
              using System.Data.OleDb;
              using System.Data.SqlClient;

              namespace WindowsFormsApplication3
              {
              public partial class Form1 : Form
              {
              public Form1()
              {
              InitializeComponent();
              }

                  private void btnBrowse\_Click(object sender, EventArgs e)
                  {
                      // Specify a Directory name or path into the File Directory TextBox
                      FolderBrowserDialog openDir = new FolderBrowserDialog();
              
                      //Choose a Directory path name and display on the File Direcotry TextBox
                      if (openDir.ShowDialog() == DialogResult.OK)
                          txtBxDir.Text = openDir.SelectedPath;
              
                      else
                          MessageBox.Show("Make sure you have selected a valid path name");
                  }
              
                  public void searchDirectory()
                  {
              
                      //Check for valid File Type and File Directory
                      if (cmbBx.Text == "") MessageBox.Show("Input a valid file type format");
                      else if (txtBxDir.Text == "") MessageBox.Show("Input a valid directory pathname");
              
                      try
                      {
                          //Search the specified Directory for files of a particular file type
                          String\[\] arrayFileList = Directory.GetFiles(txtBxDir.Text, cmbBx.Text, SearchOption.AllDirectories);
                          foreach (string file in arrayFileList)
                          {
                              string fileName = file.Substring(file.LastIndexOf("\\\\") + 1);
                              txtBxResult.Text += fileName + "\\r\\n";
                          }
              
                      }
                      catch (IOException)
                      {
                          MessageBox.Show("Choose the correct file type");
                      }
                  }
              
                  private string getTextBoxNoFiles()
                  {
                      string noFiles = txtBxResult.Lines.Length.ToString();
                      return txtBxNoFiles.Text = noFiles;
                  }
              
              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              Do you want to search for the name of a file or for the content of a file?

              H 1 Reply Last reply
              0
              • L Lost User

                Jasmine2501 wrote:

                This is C# *discussions* so I think it's ok if he doesn't have a question

                Not according to http://www.codeproject.com/Messages/1278604/How-to-get-an-answer-to-your-question.aspx[^].

                Jasmine2501 wrote:

                and shouldn't the "questions" really be going to the quick answers section or on Stack Overflow?

                No.

                Jasmine2501 wrote:

                This is the kind of thing I'd love to see here, or anywhere really... code discussions and critique is much more fun than answering dumb questions.

                Then I suspect you are at the wrong place.

                Use the best guess

                J Offline
                J Offline
                Jasmine2501
                wrote on last edited by
                #7

                Yeah I read that, but it doesn't really make sense to have a forum if that's what it is. QA is done on Stack Overflow. This site has no purpose if it doesn't allow discussion. I think it's a good post.

                L P 2 Replies Last reply
                0
                • J Jasmine2501

                  Yeah I read that, but it doesn't really make sense to have a forum if that's what it is. QA is done on Stack Overflow. This site has no purpose if it doesn't allow discussion. I think it's a good post.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Jasmine2501 wrote:

                  Yeah I read that, but it doesn't really make sense to have a forum if that's what it is.

                  Well it's been like that since Chris set it up, and everyone seems happy that it is. I don't think changing it now would go down well with the membership.

                  Use the best guess

                  J 1 Reply Last reply
                  0
                  • J Jasmine2501

                    Yeah I read that, but it doesn't really make sense to have a forum if that's what it is. QA is done on Stack Overflow. This site has no purpose if it doesn't allow discussion. I think it's a good post.

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    SO is not the only place you're allowed to do QA. It doesn't have a monopoly.

                    Jasmine2501 wrote:

                    This site has no purpose if it doesn't allow discussion.

                    Errm, the articles are the main point of the site. Everything else has been added as a service to provide a lifeline to people with code difficulties. The right place to have posted this would have been as an article (well, more likely a tip/trick), and the discussion could have followed there. As it is, this will disappear off the front page in a couple of days, and in a couple of months people will have forgotten about it.

                    I was brought up to respect my elders. I don't respect many people nowadays.
                    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                    J 1 Reply Last reply
                    0
                    • L Lost User

                      Jasmine2501 wrote:

                      Yeah I read that, but it doesn't really make sense to have a forum if that's what it is.

                      Well it's been like that since Chris set it up, and everyone seems happy that it is. I don't think changing it now would go down well with the membership.

                      Use the best guess

                      J Offline
                      J Offline
                      Jasmine2501
                      wrote on last edited by
                      #10

                      But I take that as a "sticky" with just plain good advice. It doesn't say anywhere that "this is the only thing you're allowed to do here" it's just information about how to ask good questions. I've been here many years, and we used to have good discussions, back when Chris set it up, and everyone was happy, yes, you're right about that. I clicked on a tab that says "discussions" to get here. Should be orange at the top of the page right now.

                      L 1 Reply Last reply
                      0
                      • P Pete OHanlon

                        SO is not the only place you're allowed to do QA. It doesn't have a monopoly.

                        Jasmine2501 wrote:

                        This site has no purpose if it doesn't allow discussion.

                        Errm, the articles are the main point of the site. Everything else has been added as a service to provide a lifeline to people with code difficulties. The right place to have posted this would have been as an article (well, more likely a tip/trick), and the discussion could have followed there. As it is, this will disappear off the front page in a couple of days, and in a couple of months people will have forgotten about it.

                        I was brought up to respect my elders. I don't respect many people nowadays.
                        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                        J Offline
                        J Offline
                        Jasmine2501
                        wrote on last edited by
                        #11

                        I meant the forum area. LOOK at the top of the page you are on right now. Does it not say "discussions" up there?

                        P 1 Reply Last reply
                        0
                        • J Jasmine2501

                          I meant the forum area. LOOK at the top of the page you are on right now. Does it not say "discussions" up there?

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #12

                          Given how long I have been an active contributor and question answerer here, I know full we'll what it says, and I also know what the purpose of the forums are for. You can capitalise whatever word you like, it still doesn't get away from the fact that these forums were always intended to be used for questions.

                          I was brought up to respect my elders. I don't respect many people nowadays.
                          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                          1 Reply Last reply
                          0
                          • J Jasmine2501

                            But I take that as a "sticky" with just plain good advice. It doesn't say anywhere that "this is the only thing you're allowed to do here" it's just information about how to ask good questions. I've been here many years, and we used to have good discussions, back when Chris set it up, and everyone was happy, yes, you're right about that. I clicked on a tab that says "discussions" to get here. Should be orange at the top of the page right now.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            Jasmine2501 wrote:

                            I clicked on a tab that says "discussions" to get here. Should be orange at the top of the page right now.

                            Big deal, it is titled "discussions", but everyone (apart from you) seems to accept that it actually means question and answer type discussions about technical problems, in fact the readmes at the top make it reasonably clear what the forum is used for. OK, you don't like that, so post a request in Bugs & Sugs, write a paper on it, or create a survey, because in a day or so this thread will disappear off the front page and be lost forever.

                            Use the best guess

                            J 1 Reply Last reply
                            0
                            • L Lost User

                              Jasmine2501 wrote:

                              I clicked on a tab that says "discussions" to get here. Should be orange at the top of the page right now.

                              Big deal, it is titled "discussions", but everyone (apart from you) seems to accept that it actually means question and answer type discussions about technical problems, in fact the readmes at the top make it reasonably clear what the forum is used for. OK, you don't like that, so post a request in Bugs & Sugs, write a paper on it, or create a survey, because in a day or so this thread will disappear off the front page and be lost forever.

                              Use the best guess

                              J Offline
                              J Offline
                              Jasmine2501
                              wrote on last edited by
                              #14

                              I think that is because people don't care about learning and exploring, they just want someone else to do their job. I don't see anywhere that it's a rule.

                              L 1 Reply Last reply
                              0
                              • J Jasmine2501

                                I think that is because people don't care about learning and exploring, they just want someone else to do their job. I don't see anywhere that it's a rule.

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                Jasmine2501 wrote:

                                I don't see anywhere that it's a rule.

                                You also don't see anyone supporting your view.

                                Use the best guess

                                J 1 Reply Last reply
                                0
                                • L Lost User

                                  Jasmine2501 wrote:

                                  I don't see anywhere that it's a rule.

                                  You also don't see anyone supporting your view.

                                  Use the best guess

                                  J Offline
                                  J Offline
                                  Jasmine2501
                                  wrote on last edited by
                                  #16

                                  Yes, the web site designers don't seem to be here.

                                  L P 2 Replies Last reply
                                  0
                                  • J Jasmine2501

                                    Yes, the web site designers don't seem to be here.

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    I didn't mean them, they have far too much work to do. I meant the ordinary site members who spend their time reading and answering these questions.

                                    Use the best guess

                                    1 Reply Last reply
                                    0
                                    • J Jasmine2501

                                      Yes, the web site designers don't seem to be here.

                                      P Offline
                                      P Offline
                                      Pete OHanlon
                                      wrote on last edited by
                                      #18

                                      Perhaps there's a reason that the button at the top says "Ask a question", and the sticky notes at the top of the forum bang on about questions. Maybe the web site designers had some input there.

                                      I was brought up to respect my elders. I don't respect many people nowadays.
                                      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                                      1 Reply Last reply
                                      0
                                      • B Bernhard Hiller

                                        Do you want to search for the name of a file or for the content of a file?

                                        H Offline
                                        H Offline
                                        HubSnippets
                                        wrote on last edited by
                                        #19

                                        I really intend to write an article about how the search feature of Windows Explorer can be improved. However, this post is meant to address the problem with locating and highlighting a file within the "ResultTextBox" using the "Find" button in the form. I have made attempts with "select" method but still would not work.

                                        1 Reply Last reply
                                        0
                                        • J Jasmine2501

                                          What is wrong with the built in search, and how will this be better??? I think when the app starts up, don't make the user 'select' a folder, just show a treeview of their hard drive automatically. I think you need to create some classes to separate the interface logic from the searching (and this will allow multi-threading the interface later), but that discussion is not relevant without the answer to the first question.

                                          H Offline
                                          H Offline
                                          HubSnippets
                                          wrote on last edited by
                                          #20

                                          If well built, preferably using MVS 2008, you should be able to select a directory by clicking on the "Browse" search button. When you click the search button, the directory tree of your hard drive would be displayed as "Browse For Folder" dialog box. Browse for a particular folder and click on the "Search Button". Then you can search for your preferred file type or all the files (using *.* for file type) in that directory. It is very seamless. I want to be able to select and highlight a file based on the file name the user inputs in the "TextBoxSearch".

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups