熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#遍歷文件夾返回列表類

2022-06-13   來源: .NET編程 

  using System;

  using SystemCollectionsGeneric;

  using SystemCollections;

  using SystemText;

  using SystemIO;

  namespace JiangmingxiangProgramFileList

  {

  public class FileList

  {

  //字段聲明

  private ArrayList myfilelistpath = new ArrayList();

  private ArrayList myfilelistname = new ArrayList();

  //屬性聲明

  public ArrayList GetFileListPath

  {

  get { return myfilelistpath; }

  }

  public ArrayList GetFileListName

  {

  get { return myfilelistname; }

  }

  //構造函數

  public FileList(string sourceDirectory)

  {

  DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);

  ListAll(diSource);

  }

  public void ListAll(DirectoryInfo source)

  {

  foreach (FileInfo fi in sourceGetFiles())

  {

  myfilelistpathAdd(fiFullName + fiName);

  myfilelistnameAdd(fiName);

  }

  foreach (DirectoryInfo diSourceSubDir in sourceGetDirectories())

  {

  ListAll(diSourceSubDir);

  }

  }

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/13526.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.