File count from a folder

前端 未结 10 2386
天命终不由人
天命终不由人 2020-11-27 03:47

How do I get number of Files from a folder using ASP.NET with C#?

10条回答
  •  离开以前
    2020-11-27 04:00

    You can use the Directory.GetFiles method

    Also see Directory.GetFiles Method (String, String, SearchOption)

    You can specify the search option in this overload.

    TopDirectoryOnly: Includes only the current directory in a search.

    AllDirectories: Includes the current directory and all the subdirectories in a search operation. This option includes reparse points like mounted drives and symbolic links in the search.

    // searches the current directory and sub directory
    int fCount = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Length;
    // searches the current directory
    int fCount = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).Length;
    

提交回复
热议问题