• 文件,文件夹基本操作


    1:创建文件夹用到是DirectoryInfo类的Create()方法;

    如:string name = txtName.text;

      string path = @"D:\Programe Files" + name;

      DirectoryInfo directoryInfo = new DirectoryInfo(path);

      if(directoryInfo.Exist)

          {
                MessageBox.Show("目录已存在当前文件夹");
                return;
          }
           else

      {
               directoryInfo.Create();

        MessageBox.Show("文件夹创建成功");

      }

    注意:如果DirectoryInfo directoryInfo = new DirectoryInfo(path);

       改为DirectoryInfo directoryInfo = new DirectoryInfo(name);则创建在工程下的Debug目录下。

       还可以用directoryInfo.Delete()方法删除文件夹,directoryInfo.MoveTo()方法移动文件夹,directoryInfo.GetAllFiles()方法遍历文件夹中的所有文件。

    2:创建文应用的是File类的Create()静态方法;

    如:string name = txtName.text;

      string path = @"D:\Programe Files" + name;

      File.Create(path); 则在制定位置创建了名字为name的文件;

    注意:可以调用File.Delete(path)删除文件,File.Copy(path,newPath)拷贝文件;

    3:获取文件的基本信息是用FileInfo 类来映射文件;

    如:FileInfo  fileInfo = new FileInfo(path);可以通过fileInfo来获取文件基本信息;

  • 相关阅读:
    separable-sss
    Separable Subsurface Scattering Computer Graphics Forum 2015
    GPU Gems 3》:真实感皮肤渲染技术总结
    Subsurface scattering support in Blinn-Phong material
    vue-3d-model
    Ubuntu16.04 安装显卡驱动 cuda,cudnn
    vue.js three.js component
    imagemagick Selective blur
    Leetcode 201.数字范围按位与
    Leetcode 190.颠倒二进制位
  • 原文地址:https://www.cnblogs.com/PaulMa/p/1869774.html
Copyright © 2020-2023  润新知