473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

search function for directories

134 100+
I am trying to give my program a search function which can search for directories. At the moment it can search for directories but it's only searching for the directories who have exactly the name which is put in the textbox. And I want a function that can search for every directory which has a the name, standing in the textbox. For example if I typ in the word "test" and I have 2 directories, one with the name test 1 and the other one test 2. It will have to display both directories.
If anyone knows how to create a search function like that, please tell me. I would appreciate some codes.

Many thanks in advance.
Apr 26 '11 #1
8 1986
Plater
7,872 Expert 4TB
They support wild cards. Try something like this:
string[] MatchingDirectories = Directory.GetDirectories(BasePath, "*" + SearchField + "*", SearchOption.AllDirectories);
Apr 26 '11 #2
michaeldebruin
134 100+
Thanks, but now I am getting the problem that it shows as result "string[]-matrix" and not the real and full name of the directories it found.
Apr 26 '11 #3
Plater
7,872 Expert 4TB
Well yes, you are getting an array of strings (that is a string[])
With each entry being one of the possible directories.
Apr 27 '11 #4
michaeldebruin
134 100+
And it is good that I am getting an array of strings. But I need an search function which returns all the real and full names of all the possible directories. So if you know some codes which should be able to do the work, please tell me.
Apr 27 '11 #5
Plater
7,872 Expert 4TB
What do you mean by real and full names?
Each entry in that string[] should be like:
c:\temp\files\test 1\
c:\temp\files\test 2\
c:\temp\files\franks test\

EDIT:
Now I suppose it will ALSO give you entries with your search term NOT being the lowest directory, as long as its below the basepath:
c:\temp\files\test 1\
c:\temp\files\test 2\
c:\temp\files\franks test\
c:\temp\files\test 2\somename\
c:\temp\files\franks test\try2\
Apr 27 '11 #6
michaeldebruin
134 100+
what I mean is:
if a directory name is franks test and I say search for the test. The program has to show the full directory name as in this case franks test.
And what you say each entry in that string[] should be like:
c:\temp\files\test 1\.
But the only thing my program display is "string[]-matrix".
Apr 27 '11 #7
Plater
7,872 Expert 4TB
Are you just doing MatchingDirectories.ToString() by anychance?
Try
Expand|Select|Wrap|Line Numbers
  1. foreach (string singleentry in MatchingDirectories)
  2. {
  3. //do something with the single entry
  4. }
  5.  
Apr 27 '11 #8
michaeldebruin
134 100+
the code I have at the moment is:
Expand|Select|Wrap|Line Numbers
  1. string[] MD = Directory.GetDirectories(Environment.CurrentDirectory, searchtext.Text , SearchOption.AllDirectories);
  2.  
  3.             if (MD != null)
  4.             {
  5.                 result.Items.Add(MD);
  6.                 searchtext.Clear();
  7.             }
  8.  
Apr 30 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andy Jacobs | last post by:
Hi all I have a search function on a site of mine. At the moment, the content is delivered using this: <?php echo $row_Recordset1; ?> The search function goes through the table and...
0
by: thehuby | last post by:
I want to add an Accessible search function to our website - the only way I can do this is to find a search system that can return its results as an XML document. I am currently using...
2
by: gyromagnetic | last post by:
Hi, I have written a function that searches a text string for various words. The text is searched using a boolean 'and' or a boolean 'or' of the input list of search terms. Since I need to use...
5
by: James Stroud | last post by:
Hello All, I'm using pyinstaller 1.0 (stable) on win32xp and it is not able to find the codec for several encodings (hex, base64, etc.). I resorted to writing my own for hex, just to see if I...
3
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I have a VB app, and I have been working at it for a while, and I am now at the stage where I want to create a search function. Now don't be scared! It is in the .Net compact framework,...
3
by: alexmason86 | last post by:
getting a bit stuck here got some code that allows a user to input numbers to a 3x3 array. but next on the tutorial sheet i have to then ask the user for a number to search for and then search the...
0
by: kang jia | last post by:
hi currently i am doing this search function for car booking website. it can search through either car seats or CarModel. it seems it able to do search function, however i small problem occurs to...
1
by: ashraf02 | last post by:
Someone please help! i am writing a code for a search function and everytime i execute the code i get the following error. You have an error in your SQL syntax; check the manual that corresponds...
1
by: nik707 | last post by:
Hello all, I would like to develop a date search from Form in Access. Here is the sample of previous search coding I have developed used the help of experts on this forum. 'Approach to CSR...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.