zoukankan      html  css  js  c++  java
  • WEB遍历文件夹下所有的文件(不遍历文件夹)

    1.  /// <summary>
    2.     /// 根据文件夹路径得到文件路径下所有的文件
    3.     /// </summary>
    4.     /// <param name="pathtext"></param>
    5.     public void ListFiles(string pathtext)
    6.     {
    7.         try
    8.         {
    9.             
    10.             if (pathtext == null ||pathtext.Equals(""))
    11.             {
    12.                 Response.Write("路径不能为空错误");
    13.             }
    14.             else
    15.             {
    16.                 //得到文件名,目录
    17.                 string[] filename = Directory.GetFiles(Server.MapPath(pathtext));
    18.                 //初始化文件计数器
    19.                 int a = 0;
    20.                 //初始化文件大小
    21.                 long j = 0;
    22.                 //遍历文件夹
    23.                 foreach (string file in filename)
    24.                 {
    25.                     //得到文件的创建时间
    26.                     DateTime CreationTime = File.GetCreationTime(file);//文件创建时间
    27.                     //得到符合条件的文件,某个时间段之前的文件
    28.                     //file文件地址
    29.                     Response.Write(file+"file<br/>");
    30.                     //得到文件的大小
    31.                     FileInfo f = new FileInfo(file);
    32.                     long len = f.Length;//单个文件大小
    33.                     Response.Write(len.ToString()+"文件大小<br/>");
    34.                     j = j + len;
    35.                     a++;//文件个数
    36.                 }
    37.                 //关闭窗口
    38.                 Response.Write (a.ToString()+"文件个数<br/>");//输出个数
    39.                 int i = a;
    40.                 //Response.Write(j.ToString());
    41.                 long x = j /1024;
    42.                 Response.Write(x.ToString() + "KB 文件大小<br/>");//得到大小
    43.                 Response.Write("搜索完毕!系统提示<br/>");
    44.             }
    45.         }
    46.         catch
    47.         {
    48.             Response.Write("请检查路径是否正确");
    49.         }
    50.     }
  • 相关阅读:
    (转)单机上配置hadoop
    整数划分 Integer Partition(二)
    整数划分 Integer Partition(一)
    深入理解计算机系统:信息的处理和表示(二)整数四则运算
    深入理解计算机系统:信息的处理与表示(一)基础
    从《营造法式》为何成书于北宋 谈起
    (转)排列算法 Permutation Generation
    洛谷2971 [USACO10HOL]牛的政治Cow Politics
    洛谷1549 棋盘问题(2)
    洛谷3084 [USACO13OPEN]照片Photo
  • 原文地址:https://www.cnblogs.com/dingdingmao/p/3146586.html
Copyright © 2011-2022 走看看