Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

สร้าง Directory หรือ Folder ด้วยโปรแกรม C/C++


ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมสร้าง directory หรือ folder ด้วย C/C++ program

เพื่อสร้าง directory ใหม่ เราจะใช้คำสั่ง mkdir() โค้ดนี้ทำงานได้เฉพาะ Windows compiler เท่านั้น

ตัวอย่าง

#include <conio.h>
#include <dir.h>
#include <process.h>
#include <stdio.h>
void main(){
    int check;
    char* dirname = "tutorialspoint";
    clrscr();
    check = mkdir(dirname);
    //checking if directory is created
    if (!check)
        printf("Directory created\n");
    else {
        printf("Unable to create directory\n");
        exit(1);
    }
    getch();
    system("dir/p");
    getch();
}

ผลลัพธ์

Directory created