国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

.Net Framework 4.0: Enumerating file system objects

2019-11-17 04:09:44
字體:
來源:轉載
供稿:網友
2009-10-27 20:07:44 | .net教程聚合
In my last posting I introduced new ReadLines() method and new overloads for WriteAllLines() method of File class. But there are more new stuff in System.IO namespace. In .Net Framework 4.0 Directory and DirectoryInfo class are able to enumerate files, directories and file system entries. In this posting I will show you these new features.

Let’s see now how to enumerate file system objects using new static methods of Directory class. There is one thing you should know. If you have to handle files and directories in same context then you should use EnumerateFileSystemEntries() method that enumerates both files and directories. The following example shows you how to enumerate different file system objects.


--------------------------------------------------------------------------------

static void Main(string[] args)

{

    var path = Path.GetPathRoot(Environment.CurrentDirectory);



    var files = Directory.EnumerateFiles(path);
    var directories = Directory.EnumerateDirectories(path);    
    var entries = Directory.EnumerateFileSystemEntries(path);



    Console.WriteLine("Files:");

    foreach (var file in files)

        Console.WriteLine(file);



    Console.WriteLine("/r/nDirectories:");

    foreach (var directory in directories)

        Console.WriteLine(directory);



    Console.WriteLine("/r/nEntries:");

    foreach (var entry in entries)

        Console.WriteLine(entry);



    Console.ReadLine();

}


--------------------------------------------------------------------------------

You should get output like this (the path is root path of drive where application is located).

Files:
C:/autoexec.bat
C:/config.sys
C:/pagefile.sys
  Directories:
C:/$Recycle.BinC:/Documents and Settings
C:/Install
C:/PerfLogs  C:/PRogram Files
C:/ProgramData  C:/Recovery  C:/System Volume Information  C:/Users  C:/Windows
  Entries:
C:/$Recycle.Bin
C:/autoexec.bat
C:/config.sys
C:/Documents and Settings
C:/Install
C:/pagefile.sys
C:/PerfLogs
C:/Program Files
C:/ProgramData
C:/Recovery
C:/System Volume Information
C:/Users
C:/Windows
These enumerating methods work better than ones that return arrays because requests to file system are made only when concrete object is asked from enumerator. I think these methods may be very good load balancers in applications that make heavy use of file system.
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永城市| 娱乐| 邹城市| 盘山县| 渭源县| 陵水| 收藏| 乌什县| 汶川县| 遂宁市| 延寿县| 玉溪市| 任丘市| 平江县| 通海县| 白河县| 库尔勒市| 锦屏县| 无极县| 江山市| 沁阳市| 石首市| 赣榆县| 神池县| 卓尼县| 合山市| 闵行区| 元江| 松溪县| 莲花县| 乳源| 长宁区| 陆丰市| 都昌县| 津市市| 京山县| 博爱县| 霸州市| 英吉沙县| 通江县| 郸城县|