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 . \n" , path);
}
else
{
printf("can't creat the directoty %s.\n , path");
printf("errno:%d\n",errno);
printf("ERR : %s\n",strerror(errno));
}
}
[root@centos-64-min file]# ./mkdir
created the directory /root/mkdir1 .
相关推荐
farwang 2020-11-25
星愿心愿 2020-11-24
tianhuak 2020-11-24
zhjn0 2020-11-24
昭君出塞 2020-11-23
bluecarrot 2020-11-23
linuxwcj 2020-10-21
以梦为马不负韶华 2020-10-20
彼岸随笔 2020-10-20
yutou0 2020-10-17
applecarelte 2020-10-16
ourtimes 2020-10-16
waterhorse 2020-09-19
MRFENGG 2020-11-11
rainandtear 2020-10-30
kyssfanhui 2020-10-20
liuhangtiant 2020-10-20