Saving a file and automatically create directories

后端 未结 2 374
死守一世寂寞
死守一世寂寞 2021-01-03 22:46

I am concatenating a number of variables and I want to save that string as a file path.

Is there a way it will automatically create all appropriate directories if th

相关标签:
2条回答
  • 2021-01-03 23:19
    
    using System.IO;
    ....
    Directory.CreateDirectory(@"c:\temp\a\b\c\d\e");
    
    
    0 讨论(0)
  • 2021-01-03 23:44

    Use new FileInfo(path).Directory.Create().

    (This creates anything in the hierarchy that's required. If the directory already exists it does nothing.)

    0 讨论(0)
提交回复
热议问题