zoukankan      html  css  js  c++  java
  • 利用System.IO中的Directory类对目录进行基本操作

     //创建目录
      Directory.CreateDirectory("c:\\Dir_name");     


       //删除目录
       Directory.Delete("c:\\Dir_name");
       //或
       Directory.Delete("c:\\Dir_name",false);    //当待删除目录下有文件或子目录时,抛出异常,除非第二个参数为true


       //判断一个目录是否存在
       Response.Write(Directory.Exists("c:\\Dir_name"));


       //取得目录的时间
       Response.Write(Directory.GetCreationTime("c:\\Dir_name"));


       //返回一个目录下的子目录
       string[] f1;
       f1=Directory.GetDirectories("c:\\"); 
       
       //也可写为f1=Directory.GetDirectories("c:\\","w*.*");         
       //既使用通配符为条件过滤 本例是返回以w开头的目录


       //输出
       for(int i=0;i<f1.GetLength(0);i++){
           Response.Write(f1.GetValue(i));
        Response.Write("<br>");                  //换行
       }


       //返回一个目录下的文件
       f1=Directory.GetFiles("c:\\"); 
       
       //也可写为f1=Directory.GetFiles("c:\\","w*.*");        
       //既使用通配符为条件过滤 本例是返回以w开头的文件

       //输出
       for(int i=0;i<f1.GetLength(0);i++)
       {
        Response.Write(f1.GetValue(i));
        Response.Write("<br>");                  //换行
       }

  • 相关阅读:
    批量管理服务器,批量分发文件
    IIS最大连接数优化
    在CentOS 7中安装与配置JDK8
    可扩展流程设计工具方案
    An internal erroroccurred during: "Removing compiler problem markers...".java.lang.String
    .NET和java之争实没必要
    提高生产率的VS插件
    Java Synchronized关键字
    Flex拖动实现方法
    WF3.0和4.0区别介绍
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/854251.html
Copyright © 2011-2022 走看看