在C语言中怎样新建一个文件夹?

来源:百度知道 编辑:UC知道 时间:2024/05/13 10:09:15

函数名: 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;
}

包含头文件stdlib.h后,调用system("md 文件夹名称"); 或者system("mkdir 文件夹名称");

system("mkdir 123");

其实用cmd命令和在c里写是一样的 因为c的很多函数