本文介绍了保存文件,并自动创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在串联很多变数,我想保存字符串作为文件路径。
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 they dont exist without having to check "if exists" on each one
例如是否存在。
C:\+ A +\+ B +\+ D +\+ D +名.txt
"C:\" + a + "\" + b+ "\" + d + "\" + d + ".txt"
推荐答案
使用新的FileInfo(路径).Directory.Create()
。
(这的需要的层次创造任何东西。如果该目录已经存在,它什么都不做。)
(This creates anything in the hierarchy that's required. If the directory already exists it does nothing.)
这篇关于保存文件,并自动创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!