zoukankan      html  css  js  c++  java
  • IO>File and Directory class

    The class to process the file and directory mainly include Directory, DirectoryInfo, File,  FileInfo

    Directory  : create, move, rename, delete directory with static method . if you will use a directory object many times, you’d better use DirectoryInfo class to create a DreictoryInfo object

    DirectoryInfo: be similar with Directory, only differece is that it need to create a object

    File: create, move, rename, delete file with static method
    FileInfo: be similar with File, only difference is that it uses to create, move, rename, delete file  by Creating FileInfo Object

    Samples:
    protected DataTable CreateDataSource()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("filename", typeof(string));
            dt.Columns.Add("size", typeof(int));
            dt.Columns.Add("type", typeof(int));
            dt.Columns.Add("modified", typeof(DateTime));
            //dt.DefaultView.Sort = "type," + dgFiles.GetOrderBy();
            return dt;
        }

    DirectoryInfo dirInfo = new DirectoryInfo(“c:\”);
                FileInfo[] info = dirInfo.GetFiles();
                DirectoryInfo[] dirs = dirInfo.GetDirectories();
                DataTable dt = CreateDataSource();// undefined!!!
                DataRow dr;

                foreach (DirectoryInfo dir in dirs)
                {
                    dr = dt.NewRow();
                    dr["filename"] = dir.Name;
                    dr["size"] = "0";
                    dr["type"] = "0";
                    dt.Rows.Add(dr);
                }

                foreach (FileInfo file in info)
                {
                    dr = dt.NewRow();
                    dr["filename"] = file.Name;
                    dr["size"] = (int)file.Length / 1024;
                    dr["type"] = "1";
                    dr["modified"] = file.LastWriteTime;
                    dt.Rows.Add(dr);
                }

     

  • 相关阅读:
    MVP架构模型的一些延伸笔记
    Google 新建议
    ComboBox控件“设置 DataSource 属性后无法修改项集合”的解决【转】
    2013年省市区/县数据SQL Server(SQL语句)
    MAC下搭建个人博客
    MAC MYSQ忘记密码重置方法
    Web设计中打开新页面或页面跳转的方法
    策划书模版
    网站书签
    Swift
  • 原文地址:https://www.cnblogs.com/Winston/p/1026478.html
Copyright © 2011-2022 走看看