当前位置:首页 » 文件管理 » 如果文件夹不存在则创建

如果文件夹不存在则创建

发布时间: 2023-05-21 23:25:23

1. java文件上传如果文件不存在则创建

应该是文件夹不存在就创建的吧。
File headPath = new File(uploadPath);//获取文件夹路径模拆
if(!headPath.exists()){//判断文团码枣件夹是否创建,塌拆没有创建则创建新文件夹
headPath.mkdirs();
}

2. php判断文件夹是否存在不存在则创建

php判断文件夹是否存在用到的工具:notepad++,代码如下:

functionmkdirs($a1,$mode=0777)
{
if(is_dir($a1)||@mkdir($al,$mode))returnTRUE;
if(!mkdirs(dirname($a1),$mode))returnFALSE;
return@mkdir($a1,$mode);
}
mkdirs("a1");

说明:程序判断a1这个目录是否存在,如果存在就返回真,如果不存在就创建a1目录,默认给与读写和执行的权限。

注意事项:777权限适用于linux环境。

3. C#判断文件和文件夹是否存在 不存在则创建

if (Directory.Exists(Server.MapPath(~/upimg/hufu)) == false)//如果不存在就创建file文件夹{ Directory.CreateDirectory(Server.MapPath(~/upimg/hufu));} //Directory.Delete(Server.MapPath(~/upimg/hufu), true);//删除文件夹以及文件夹中的子目录,文件 //判断文件的存在 if (File.Exists(Server.MapPath(~/upimg/Data.html))){ Response.Write(Yes);//存在旅银文件}else{ Response.Write(No); //不存在文件 File.Create(MapPath(~/upimg/Data.html));//创建该文件} string name = GetFiles.FileName;//获取已上传明卜文件的名字 string size = GetFiles.PostedFile.ContentLength.ToString();//获取已上传文件的大小 string type = GetFiles.PostedFile.ContentType;//获取已上传文件的MIME string postfix = name.Substring(name.LastIndexOf(.) + 1);//获取已上传文件的后缀 string ipath = Server.MapPath(upimg) +\\+ name;//获取文件的实际路径 string fpath = Server.MapPath(upfile) + \\ + name; string dpath = upimg\\ + name;//判断写入数据库的虚拟路径 ShowPic.Visible = true;//激活 ShowText.Visible = true;//激活 //判断文件格式 if (name == ) { Response.Write(<scriptalert('上传文件不能为空')</script);}else{ if (postfix == jpg || postfix == gif || postfix == bmp || postfix == png){ GetFiles.SaveAs(ipath); ShowPic.ImageUrl = dpath; ShowText.Text = 你上传的图片名称是: + name + + 文件大小: + size + KB + + 文件类型: + type + + 存放的实际路径为: + ipath;}else{ ShowPic.Visible = false;//隐藏图片 GetFiles.SaveAs(fpath);//由于不是图片文件,因此转存在upfile这个文件夹拆槐宴 ShowText.Text = 你上传的文件名称是: + name + + 文件大小: + size + KB + + 文件类型: + type + + 存放的实际路径为: + fpath;}

4. php判断文件夹是否存在不存在则创建

//直接这样即可:
$dir='./test/test';
is_dir($dir)ORmkdir($dir,0777,true);//如果文件夹不存在,将以递归方式创建该文件夹

5. 批处理 判断一个文件夹是否存在,不存在则创建,求大神指导。。谢谢

用IF NOT EXIST "G:\%DATE:~0,10%tst" MD "G:\%DATE:~0,10%tst"

例如:

IF EXIST C:DATE (

del filename.

) ELSE (

echo filename. missing.

)

(5)如果文件夹不存在则创建扩展阅读:

注意事项

@echo off

@title 批处理判断文件夹是否存在

if exist folder1 (

echo "已销告笑经存在文件夹"

) else (

md folder1

)

if not exist folder2 md folder2

pause

命令中首先判断当前目录友岩中是否存在folder1,如亏含果存在,打印“已经存在文件夹”如果不存在就用md命令建立文件夹。

6. php判断文件夹是否存在不存在则创建

if(file_exists($file)) 存在;
else 不存在;
if(is_dir($dir)) 存在;
else 不存在;
mkdir($dir); //创建文件夹
file_put_contents('文件路径', '文件内容');//创建文件

7. 在C++中如何判断文件夹是否存在,不存在的话创建文件夹

参考代码如下:
#include <stdio.h>
#include <direct.h>
#include <stdlib.h>
#include <memory>
//检查文件夹是否存在,不存在则创建之
//文件夹存在返回 0
//文件夹创建失败返回-1
//文件夹创建失败返回1
int CheckDir(char* Dir)
{
FILE *fp = NULL;
char TempDir[200];
memset(TempDir,'\0',sizeof(TempDir));
sprintf(TempDir,Dir);
strcat(TempDir,"\\");
strcat(TempDir,".temp.fortest");
fp = fopen(TempDir,"w");
if (!fp)
{
if(_mkdir(Dir)==0)
{
return 1;//文件夹创建成功
}
else
{
return -1;//can not make a dir;
}
}
else
{
fclose(fp);
}
return 0;
}

8. c++ 判断文件夹是否存在,不存在则创建

c++中,<io.h>中的_access可以判断文件是否存在,<direct.h>中的_mkdir可以创建文件。

---------------------------------------------

建单级目录:

#include <io.h>

#include <direct.h>

#include <string>

int main()

{

std::string prefix = "G:/test/";

if (_access(prefix.c_str(), 0) == -1) //如果文件夹不存在

_mkdir(prefix.c_str()); //岩闹尺则创建

}

----------------------------------------------------

建多级目录:

最后一个如果是文件粗高夹的话,需要加上 '\\' 或者 '/'

#include <io.h>

#include <direct.h>

#include <string>

int createDirectory(std::string path)

{

int len = path.length();

char tmpDirPath[256] = { 0 };

for (int i = 0; i < len; i++)

{

tmpDirPath[i] = path[i];

if (tmpDirPath[i] == '\\'弯芦 || tmpDirPath[i] == '/')

{

if (_access(tmpDirPath, 0) == -1)

{

int ret = _mkdir(tmpDirPath);

if (ret == -1) return ret;

}

}

}

return 0;

}

9. Java判断文件夹是否存在,不存在就创建

方法如下:

public static void judeDirExists(File file)

if (file.exists()) if (file.isDirectory())

System.out.println("dir exists"); }

else System.out.println("the same name file exists, can not create dir"); }41

else System.out.println("dir not exists, create it ..."); 、

file.mkdir();

热点内容
Ftp打开文件是只读模式 发布:2025-02-09 07:40:55 浏览:504
androidlistview点击事件 发布:2025-02-09 07:25:52 浏览:171
targz解压缩 发布:2025-02-09 06:59:19 浏览:311
wpsphp 发布:2025-02-09 06:58:41 浏览:961
视易锋云系统如何架设辅助服务器 发布:2025-02-09 06:47:08 浏览:770
mysql备份脚本shell 发布:2025-02-09 06:46:33 浏览:15
腾讯云服务器怎样调整分辨率 发布:2025-02-09 06:46:30 浏览:369
php上一个页面 发布:2025-02-09 06:41:25 浏览:489
改装配置后不想重启怎么办 发布:2025-02-09 06:36:40 浏览:446
算法复杂度定义 发布:2025-02-09 06:30:46 浏览:587