DirectoryInfo.GetFiles() : DirectoryInfo « System.IO « C# / C Sharp by API






DirectoryInfo.GetFiles()

  
using System;
using System.IO;
public class FileSearch {
    public static void Main() {
        String searchName = "win";
        DirectoryInfo myDir = new DirectoryInfo(@"c:\Program Files");
        SearchDirectories(myDir, searchName);
    }

    public static void SearchDirectories(DirectoryInfo dir, String target) {
        FileInfo[] files = dir.GetFiles();
        foreach (FileInfo file in files) {
            if (file.Name.IndexOf(target) > -1) {
                Console.WriteLine(file.Name);
            }
        }

        DirectoryInfo[] dirs = dir.GetDirectories();
        foreach (DirectoryInfo subDir in dirs) {
            SearchDirectories(subDir, target);
        }
    }
}

   
    
  








Related examples in the same category

1.new DirectoryInfo(String path)
2.DirectoryInfo.CreateSubdirectory
3.DirectoryInfo.CreationTime
4.DirectoryInfo.Exists
5.DirectoryInfo.FullName
6.DirectoryInfo.GetDirectories()
7.DirectoryInfo.GetFiles(String filter)
8.DirectoryInfo.LastAccessTime
9.DirectoryInfo.LastWriteTime
10.DirectoryInfo.Name
11.DirectoryInfo.Parent