C# Directory.GetFileSystemEntries(path) Directory.EnumerateFileSystemEntries(path)

using System;
using System.IO;

 static void Main(string[] args)
 {
     DirectoryDemo();  
 }

 static void DirectoryDemo()
 {
     string path = "D:\\C\\ConsoleApp13";
     Console.WriteLine($"Directory.GetCurrentDirectory():{Directory.GetCurrentDirectory()}");
     Console.WriteLine($"Directory.GetParent(path):{Directory.GetParent(path)}");
     Console.WriteLine($"Directory.GetDirectoryRoot(path):{Directory.GetDirectoryRoot(path)}");

     var logicalDrivers = Directory.GetLogicalDrives();
     if(logicalDrivers != null && logicalDrivers.Any())
     {
         foreach(var logicalDriver in logicalDrivers) 
         {
             Console.WriteLine($"Directory.GetLogicalDrives():{logicalDriver}");
         } 
     }

     string[] dirs = Directory.GetDirectories(path);
     if(dirs!=null && dirs.Any())
     {
         foreach(var dir in dirs)
         {
             Console.WriteLine($"Directory.GetDirectories(path):{dir}");
         }
     }

     string[] systemEntries = Directory.GetFileSystemEntries(path);
     if(systemEntries != null && systemEntries.Any())
     {
         foreach(var systemEntry in systemEntries)
         {
             Console.WriteLine($"Directory.GetFileSystemEntries(path):{systemEntry}");
         }
     }

     var enumerableFiles=Directory.EnumerateFiles(path);
     if(enumerableFiles!= null && enumerableFiles.Any())
     {
         foreach(var enumerableFile in enumerableFiles)
         {
             Console.WriteLine($"Directory.EnumerateFiles(path):{enumerableFile}");
         }
     }

     var enumerateDirs=Directory.EnumerateDirectories(path);
     if(enumerateDirs!=null && enumerateDirs.Any())
     {
         foreach (var enumerateDir in enumerateDirs)
         {
             Console.WriteLine($"Directory.EnumerateDirectories(path):{enumerateDir}");
         }
     }

     var enumerateSystemEntries = Directory.EnumerateFileSystemEntries(path);
     if(enumerateSystemEntries!=null && enumerateSystemEntries.Any())
     {
         foreach(var enumerateEntry in enumerateSystemEntries)
         {
             Console.WriteLine($"Directory.EnumerateFileSystemEntries(path):{enumerateEntry}");
         }
     }
 }

  

 

posted @ 2024-02-28 22:56  FredGrit  阅读(12)  评论(0编辑  收藏  举报