如果文件夹不存在,创建它 [英] If a folder does not exist, create it

查看:168
本文介绍了如果文件夹不存在,创建它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的应用程序FileUploader控制。我想将文件保存在指定文件夹。现在我想,如果这个文件夹不存在,首先创建它,然后我的文件保存到这个文件夹。如果文件夹已经存在,那么就保存在文件中了。

I use a FileUploader control in my application. I want to save a file in a specified folder. Now I want, if this folder does not exist, to first create it, and then save my file to this folder. If the folder already exists, then just save the file in it.

我怎样才能做到这一点?

How I can do this?

推荐答案

正如其他人所说,使用System.IO.Directory.CreateDirectory

As others have said, use System.IO.Directory.CreateDirectory

但是,你并不需要检查它是否存在第一。从文档

But, you don't need to check if it exists first. From the docs

任何和路径指定的所有目录中创建的,除非他们
  已经存在或除非路径的某些部分是无效的。路径
  参数指定的目录路径,而不是一个文件路径。如果
  目录已经存在,这个方法不起作用。

Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. The path parameter specifies a directory path, not a file path. If the directory already exists, this method does nothing.

这篇关于如果文件夹不存在,创建它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆