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来获取文件基本信息;

 

 

相关文章:

  • 2021-09-17
  • 2022-02-07
  • 2022-01-22
  • 2021-05-26
  • 2022-01-14
  • 2022-02-19
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2021-10-12
  • 2021-08-09
  • 2021-06-24
  • 2021-11-20
  • 2021-11-06
  • 2021-11-06
  • 2021-09-28
相关资源
相似解决方案