File search

Is there anything in the .net library that would allow me to search for a file on a pc, ie. sql2005 installer I need a method that allows me to search specific locations for specified files rather than just checking a predefined path ie File.Exists(filename) as the user may have moved those files to a different location.

ta

Mark



Answer this question

File search

  • Jason Jaegers

    so I could just set the folder path as the C:\ drive and let it search that drive and all its folders for the application ...
  • arkiboys

    Indeed, correction, multiple parent directories...

  • DotNet Programmer

    However, to search multiple directories you'd have to implement yourself.

  • Henk Gijsbert

    Just keep in mind that this could take a heck of a long time, so it'd probably be best if you did it in a background thread. Providing progress information would also not be possible with AllDirectories, it's either running or finished. Of course, if you rolled your own directory recursion for the search, you'd get progress, but probably at the expense of overall speed.



  • Klaus Prückl

    Hi,

    My case is something diff.

    I want to search .js files from one remote machine(server) copy it and paste it at diff server(machine) with sub folders if exist. PLease help to figure it out.



  • Pawel W.

    Yes, indeed. It is possible to search subdirectories with the above function by setting the SearchOption.

    Greetz,

    Geert

    Geert Verhoeven
    Consultant @ Ausy Belgium

    My Personal Blog



  • torvaldson

    I have written an asynchronous file search component, you can find the blog post describing it at http://dotnet.org.za/codingsanity/archive/2007/02/21/writing-an-asynchronous-component.aspx, and the source code for it at http://www.codingsanity.com/code/Sanity%20Shared.zip



  • lib_team

    Hi,

    To do this, you need to use the System.IO.Directory class. One of its members is GetFiles(string path, string searchPattern, SearchOption searchOption) which returns an array of files that match the specified pattern.

    Greetz,

    Geert

    Geert Verhoeven
    Consultant @ Ausy Belgium

    My Personal Blog



  • EBeckers

    I'm somewhat new to .Net and I tried this sample but got the following error when I use c:\ as the root.

    Access to the path 'c:\System Volume Information' is denied.

    Is there something I can do to tell it to ignore errors or exceptions

    Using something higher up in the tree worked fine.

    Thanks

    Dan


  • Alan Robbins

    Yes, that's correct. You just need to code something like this:

    string[] files = System.IO.Directory.GetFiles(@"C:\", "*.txt", System.IO.SearchOption.AllDirectories);

    Greetz,

    Geert

     

    Geert Verhoeven
    Consultant @ Ausy Belgium

    My Personal Blog



  • File search