- /// <summary>
- /// 根据文件夹路径得到文件路径下所有的文件
- /// </summary>
- /// <param name="pathtext"></param>
- public void ListFiles(string pathtext)
- {
- try
- {
- if (pathtext == null ||pathtext.Equals(""))
- {
- Response.Write("路径不能为空错误");
- }
- else
- {
- //得到文件名,目录
- string[] filename = Directory.GetFiles(Server.MapPath(pathtext));
- //初始化文件计数器
- int a = 0;
- //初始化文件大小
- long j = 0;
- //遍历文件夹
- foreach (string file in filename)
- {
- //得到文件的创建时间
- DateTime CreationTime = File.GetCreationTime(file);//文件创建时间
- //得到符合条件的文件,某个时间段之前的文件
- //file文件地址
- Response.Write(file+"file<br/>");
- //得到文件的大小
- FileInfo f = new FileInfo(file);
- long len = f.Length;//单个文件大小
- Response.Write(len.ToString()+"文件大小<br/>");
- j = j + len;
- a++;//文件个数
- }
- //关闭窗口
- Response.Write (a.ToString()+"文件个数<br/>");//输出个数
- int i = a;
- //Response.Write(j.ToString());
- long x = j /1024;
- Response.Write(x.ToString() + "KB 文件大小<br/>");//得到大小
- Response.Write("搜索完毕!系统提示<br/>");
- }
- }
- catch
- {
- Response.Write("请检查路径是否正确");
- }
- }