File count from a folder

前端 未结 10 2412
天命终不由人
天命终不由人 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:11

    To get the count of certain type extensions using LINQ you could use this simple code:

    Dim exts() As String = {".docx", ".ppt", ".pdf"}
    
    Dim query = (From f As FileInfo In directory.GetFiles()).Where(Function(f) exts.Contains(f.Extension.ToLower()))
    
    Response.Write(query.Count())
    

提交回复
热议问题