Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Linux C目录与文件:创建目录

创建目录函数:mkdir 函数原型:int mkdir(char * pathname , mode_t mode);pathname字符指针是表示需要创建的目录路径,mode表示权限的八进制数字。创建成功返回整形数0,否则返回整数-1头文件:sys/types.h 和 sys/stat.h例子:[root@CentOS-64-min file]# cat mkdir.c
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<errno.h>
int main(void)
{
 extern int errno;
 char * path = "/root/mkdir1";if(mkdir(path , 0766)==0)
 {
 printf("created the directory %s . " , path);
 }
 else
 {
 printf("can"t creat the directoty %s. , path");
 printf("errno:%d ",errno);
 printf("ERR : %s ",strerror(errno));
 }
}
[root@centos-64-min file]# ./mkdir
created the directory /root/mkdir1 .本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/128791.htm