asp.net i/o建立目錄列表執行個體

來源:互聯網
上載者:User

asp教程.net i/o建立目錄列表執行個體


下面的程式碼範例顯示了如何使用 io 類來建立目錄列表。
[c#]

using system;
using system.io;
class directorylister
{
  public static void main(string[] args)
  {
  directoryinfo dir = new directoryinfo(".");
  foreach (fileinfo f in dir.getfiles("*.cs"))
  {
  string name = f.fullname;
  long size = f.length;
  datetime creationtime = f.creationtime;
  console.writeline("{0,-12:n0} {1,-20:g} {2}", size,
  creationtime, name);
  }
  }
}


在本樣本中,directoryinfo 對象是目前的目錄,用 (".") 表示,代碼列出了目前的目錄中具有 .cs 副檔名的所有檔案,同時還列出了這些檔案的大小、建立時間和名稱。假設 c:mydir 的 bin 子目錄中存在多個 .cs 檔案,該代碼的輸出可能如下所示:
953 7/20/2000 10:42 am c:mydirbinparamatt.cs
664 7/27/2000 3:11 pm c:mydirbintst.cs
403 8/8/2000 10:25 am c:mydirbindirlist.cs


如果您要另一個目錄中檔案的列表,例如 c: root 目錄,請記著使用反斜線 () 轉義符,如"c:\"中的反斜線。您也可以使用 unix 樣式的斜杠,如"c:/"中的斜杠。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.