Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Files and Streams > Examining Directories

Examining Directories

Our InspectDirectories method calls the static GetFiles method on the Directory class to find the files we’re interested in. Example 11-5 shows the relevant code.

Example 11-5. Getting the files in a directory

var searchOption = recurseIntoSubdirectories ?
    SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

// Get the path of every file in every directory we're searching.
var allFilePaths = from directory in directoriesToSearch
                   from file in Directory.GetFiles(directory, "*.*",
                                                        searchOption)
                   select file;

The overload of GetFiles we’re calling takes the directory we’d like to search, a filter (in the standard command-line form), and a value from the SearchOption enumeration, which determines whether to recurse down through all the subfolders.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint