遍历文件下所有文件

 
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if(!IsPostBack){
  4.         string paths = @"F:/学习专用文件夹/网页";
  5.         Boolean flag = ReadFiles(paths);
  6.         if (flag)
  7.         {
  8.             Txtmess.Text = Directory.GetFiles(paths).ToString();
  9.         }
  10.         else
  11.         {
  12.             Response.Write("对不起,有误");
  13.         }
  14.     }
  15.     }
  16.     private Boolean ReadFiles(string dirroot)
  17.     {
  18.         Boolean flag = false;
  19.         string[] rootdirs = Directory.GetDirectories(dirroot);//当前目录的子目录
  20.         string[] rootFiles = Directory.GetFiles(dirroot);//目录下的文件
  21.         try
  22.         {
  23.             foreach (string s2 in rootFiles)
  24.             {
  25.                 Response.Write(s2+"<br/>");
  26.             }
  27.             foreach (string s1 in rootdirs)
  28.             {
  29.                 ReadFiles(s1);
  30.             }
  31.             flag = true;
  32.         }
  33.         catch (Exception ex)
  34.         {
  35.             throw new Exception(ex.Message);
  36.         }
  37.         return flag;
  38.     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值