File.AppendAllText create subdirectory if doesn't exist?

前端 未结 1 953
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 04:23

If I have a path C:\\Test\\Test1\\a.txt and Test1 doesn\'t exist, how can I ensure it is created before appending to a.txt?

1条回答
  •  甜味超标
    2021-02-20 05:13

    How about:

    Directory.CreateDirectory(Path.GetDirectoryName(filename));
    

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