
功 能: 建立一个目录(文件夹)
用 法: int mkdir(char *pathname)
程序例: (在win-tc和Dev-c++下运行通过)
#include <stdio.h>
#include <process.h>
#include <dir.h>
int main(void)
{
int status
system("cls")
status = mkdir("book")/*这是在程序所在当前文件夹下创建book*/
(!status) ? (printf("Directory created\n")) :
(printf("Unable to create directory\n"))
system("pause")
system("dir")/*显示创建后当前文件夹下的文件信息*/
system("pause")
status = rmdir("book")/*删除创建的文件夹book*/
(!status) ? (printf("Directory deleted\n")) :
(perror("Unable to delete directory"))
system("pause")
return 0
}
创建文件夹有两个方法:
①使用cmd命令mkdir,举例:system("mkdir D:\\dic")这条命令执行mkdir程序,在D盘创建一个文件夹dic。
②使用windows提供的CreateDictionary函数,需要包含头文件windows.h,使用方法:
CreateDictionary("D:\\dic", NULL)同样在D盘创建一个文件夹dic,因为转义字符的问题所以用两个斜杠。
这个命令和函数我就不详细解释了,分别参考mkdir和CreateDictionary的百度百科。
这里强调一下,这里说的mkdir是cmd命令,CreateDictionary是windows API函数。
函数名:mkdir
功
能:
建立一个目录(文件夹)
用
法:
int
mkdir(char
*pathname)
程序例:
(在win-tc和Dev-c++下运行通过)
#include
<stdio.h>
#include
<process.h>
#include
<dir.h>
int
main(void)
{
int
status
system("cls")
status
=
mkdir("book")
/*这是在程序所在当前文件夹下创建book*/
(!status)
?
(printf("Directory
created\n"))
:
(printf("Unable
to
create
directory\n"))
system("pause")
system("dir")
/*显示创建后当前文件夹下的文件信息*/
system("pause")
status
=
rmdir("book")
/*删除创建的文件夹book*/
(!status)
?
(printf("Directory
deleted\n"))
:
(perror("Unable
to
delete
directory"))
system("pause")
return
0
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)