Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can search an entire tree for a file using <a href="http://msdn.microsoft.com/en-us/library/ms143316.aspx" rel="nofollow">Directory.GetFiles(path,searchPattern,SearchOption)</a> or <a href="http://msdn.microsoft.com/en-us/library/dd383571.aspx" rel="nofollow">Directory.EnumerateFiles</a> with <a href="http://msdn.microsoft.com/en-us/library/ms143448.aspx" rel="nofollow">SearchOption.AllDirectories</a>, eg</p> <pre><code>var fullPaths=Directory.GetFiles(myPath,"abc.xml",SearchOption.AllDirectories) </code></pre> <p>You can also use the DirectoryInfo class to get full FileInfo instances instead of just the paths, with access to file properties and attributes:</p> <pre><code>var myDir=new DirectoryInfo(myPath); var fileInfos=myDir.GetFiles("abc.xml",SearchOption.AllDirectories); </code></pre> <p>The difference between the GetFiles and EnumerateFiles methods is that the first returns an array with all the files found, blocking until it finds all of them. <a href="http://msdn.microsoft.com/en-us/library/dd383689.aspx" rel="nofollow">EnumerateFiles</a> on the other hand returns results as it finds them, so you get to process the results much sooner.</p> <p>What goes for GetFiles goes for the <a href="http://msdn.microsoft.com/en-us/library/ms143314.aspx" rel="nofollow">GetDirectories</a>/<a href="http://msdn.microsoft.com/en-us/library/dd383462.aspx" rel="nofollow">EnumerateDirectories</a> set of functions as well. The methods are available both from the Directory and DirectoryInfo class.</p> <p>If you want to search for both directories and files, you can use <a href="http://msdn.microsoft.com/en-us/library/dd383460.aspx" rel="nofollow">GetFileSystemEntries</a>/<a href="http://msdn.microsoft.com/en-us/library/dd383459.aspx" rel="nofollow">EnumerateFileSystemEntries</a> to return both of them with a single call. The equivalent DirectoryInfo methods are <a href="http://msdn.microsoft.com/en-us/library/dd383457.aspx" rel="nofollow">GetFileSystemInfos</a>/<a href="http://msdn.microsoft.com/en-us/library/dd383457.aspx" rel="nofollow">EnumerateFileSystemInfos</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload