-5

I am writing simple program that will assist me to configure and sort out my files.I want the algorithm to search for matching string or text that the user inputs in the search box like windows search index , Google,or any other search engines.I doesn't have to be complex,just simple.you can show me by example or direct me to the appropriate resource.

HackerMan
  • 904
  • 7
  • 11
  • 1
    You should narrow this down to the specific bit you're having trouble with. – hatchet - done with SOverflow Dec 10 '15 at 17:16
  • my trouble is how to start in the first place.I am new to programming. – HackerMan Dec 10 '15 at 17:17
  • I don't think it is a duplicate – HackerMan Dec 10 '15 at 17:23
  • Are you searching file names, or file contents? If contents, the link above, as well as http://stackoverflow.com/questions/6183809/using-streamreader-to-check-if-a-file-contains-a-string and http://stackoverflow.com/questions/2437716/search-text-file-using-c-sharp-and-display-the-line-number-and-the-complete-line answer the general question of searching for text in a file. The question already has answers on stackoverflow. – hatchet - done with SOverflow Dec 10 '15 at 17:29
  • @hatchet 2 ,File Names – HackerMan Dec 10 '15 at 17:31
  • searching filenames http://stackoverflow.com/questions/1584711/how-do-i-search-for-a-list-of-files-using-wildcard or http://stackoverflow.com/questions/22938445/search-for-specific-file-name-in-directory or http://stackoverflow.com/questions/5410611/c-sharp-search-for-matching-filenames-in-a-directory-using-searchoption – hatchet - done with SOverflow Dec 10 '15 at 17:37

1 Answers1

1

https://support.microsoft.com/sv-se/kb/303974

Has some information that will get you going.

Edit: string[] files = Directory.GetFiles("C:\\", "*.dll");

This line will search through all files in c:\ for a file thats ending with .dll

Now you want it to search through all files that starts with something then youd have to run "yourstring*". In your example case, you only remember the starting "tes". Directory.GetFiles("C:\\", "tes*"); This line will search for a file starting with the filename "tes"

You can also use Directory.GetDirectories("C:\\"); to get all directories in c:\ and if you want then, loop through those directories with the same method to find all the subdirectories, then search for your file in all of those directories.

user3621898
  • 589
  • 5
  • 24
  • I dont think you get what I am saying,I said searching string,like google does.Not for directories! – HackerMan Dec 10 '15 at 17:26
  • Well you are saying that you want something to help you with your files. So I assume you are not talking about a full search engine online like google. – user3621898 Dec 10 '15 at 17:28
  • I took Google as an example,Just simple,to search files. – HackerMan Dec 10 '15 at 17:29
  • Whats wrong with the Directory.GetFiles method ? Use the GetDirectories method and loop through all directories while searching for your file with the getfiles method. – user3621898 Dec 10 '15 at 17:33
  • If im not mistaken the complete code sample from my link, helps you do exactly what you want. Search through directories to find a file – user3621898 Dec 10 '15 at 17:35
  • Don't post just a link as an answer. After sometime, link may be broken, then your answer will be useless. Try to explain what it says here instead ! – ThisaruG Dec 10 '15 at 17:37
  • Let as assume I have a file name "test1",and I only remember " tes",If I type the text ''tes",It will list all files which star with the text "tes", – HackerMan Dec 10 '15 at 17:37