zoukankan      html  css  js  c++  java
  • 获得指定目录下的 文件和子目录

    FileInfo fi;
       DirectoryInfo di;
       TableCell td;
       TableRow  tr;

       /*
        设定Table中的数据
        首先搞定第一行
       */
       tr = new TableRow();

       td = new TableCell();
       td.Controls.Add(new LiteralControl("<img src='name.gif'>"));
       tr.Cells.Add(td);

       td = new TableCell();
       td.Controls.Add(new LiteralControl("<img src='size.gif'>"));
       tr.Cells.Add(td);

       td = new TableCell();
       td.Controls.Add(new LiteralControl("<img src='lastmodify.gif'>"));
       tr.Cells.Add(td);

       tbDirInfo.Rows.Add(tr);

       string FileName;   //文件名称
       string FileExt;    //文件扩展名
       string FilePic;    //文件图片
       long FileSize;    //文件大小
       DateTime FileModify;  //文件更新时间

       DirectoryInfo dir = new DirectoryInfo(strCurrentDir);
       foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
       {
        FilePic = "";
        FileName = "";
        FileExt = "";
        FileSize = 0;

        if(fsi is FileInfo)
        {
         //表示当前fsi是文件
         fi = (FileInfo)fsi;
         FileName = fi.Name;
         FileExt  = fi.Extension;
         FileSize = fi.Length;
         FileModify = fi.LastWriteTime;
         //通过扩展名来选择文件显示图标
         switch(FileExt)
         {
          case ".gif":
           FilePic = "gif.gif";
           break;
          default:
           FilePic = "other.gif";
           break;
         }
         FilePic = "<img src='"+FilePic+"' width=25 height=20>";
        }
        else
        {
         //当前为目录
         di = (DirectoryInfo)fsi;
         FileName = di.Name;
         FileModify = di.LastWriteTime;
         FilePic = "<img src='directory.gif' width=25 height=20>";
        }

        //组建新的行
        tr = new TableRow();

        td = new TableCell();
        td.Controls.Add(new LiteralControl(FilePic+"&nbsp;"+FileName));
        tr.Cells.Add(td);

        td = new TableCell();
        td.Controls.Add(new LiteralControl(FileSize.ToString()));
        tr.Cells.Add(td);

        td = new TableCell();
        td.Controls.Add(new LiteralControl(FileModify.ToString()));
        tr.Cells.Add(td);

        tbDirInfo.Rows.Add(tr);
       }

  • 相关阅读:
    程序模块化 与 单元测试
    【集美大学1411_助教博客】2017软件工程开跑啦。。。。
    沟通很重要
    参赛感言
    助教日志_期末总结
    助教日志_【沈阳航空航天大学软件工程 1,2班】期末排行
    [数据库事务与锁]详解一: 彻底理解数据库事务
    [数据库事务与锁]详解二: 数据库的读现象浅析
    [数据库事务与锁]详解三: 深入分析事务的隔离级别
    [数据库事务与锁]详解四: 数据库的锁机制
  • 原文地址:https://www.cnblogs.com/RobotTech/p/537294.html
Copyright © 2011-2022 走看看