• 获得指定目录下的 文件和子目录


    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);
       }

  • 相关阅读:
    反调试:ZwQueryInformationProcess
    反调试:检测类名与标题名
    对某个区间操作(sort,stable_sort,parital_sort,parital_sort_copy,nth_element,is_sorted)
    数值算法(accumluate,inner_product,partial_sum,adjacent_difference,power,itoa)
    随机重拍与抽样(random_shuffle,random_sample,random_sample_n)
    分割(partition,stable_partition)
    子序列匹配(search,search_n,adjcent_find,find,find_if,find_first_of,find_end)
    MySQL管理实务处理
    MySQL触发器
    MySQL使用游标
  • 原文地址:https://www.cnblogs.com/RobotTech/p/537294.html
Copyright © 2020-2023  润新知