কম্পিউটার টিউটোরিয়াল

সকল ফাইল এবং ফোল্ডার প্রিন্ট করার C প্রোগ্রাম


ফাইল হলো রেকর্ডের একটি সংগ্রহ (অথবা) হার্ড ডিস্কে এমন একটি জায়গা যেখানে ডেটা স্থায়ীভাবে সংরক্ষিত থাকে।

C কমান্ড ব্যবহার করে আমরা ফাইলগুলোকে ভিন্ন ভিন্ন উপায়ে অ্যাক্সেস করতে পারি।

ফাইল অপারেশন

C প্রোগ্রামিং ভাষায় ফাইলগুলোর ওপর নিচের অপারেশনগুলো করা যায়:

  • ফাইল নামकरण
  • ফাইল খোলা
  • ফাইল থেকে পড়া
  • ফাইলে লেখা
  • ফাইল বন্ধ করা

সিনট্যাক্স

ফাইল খোলা এবং নামकरण এর সিনট্যাক্স নিচে দেওয়া হলো:

FILE *File pointer;

উদাহরণ: FILE * fptr;

File pointer = fopen (“File name”, “mode”);

উদাহরণ: fptr = fopen (“sample.txt”, “r”);

FILE *fp; fp = fopen (“sample.txt”, “w”);

ফাইল থেকে পড়ার সিনট্যাক্স নিম্নরূপ:

int fgetc( FILE * fp );// read a single character from a file

ফাইলে লেখার সিনট্যাক্স নিম্নরূপ:

int fputc( int c, FILE *fp ); // write individual characters to a stream

প্রোগ্রাম সংরক্ষিত করেন্ট ডিরেক্টরির ফাইল এবং ফোল্ডারগুলো দেখানোর লজিক নিচে ব্যাখ্যা করা হলো:

dr = opendir("."); if(dr!=NULL){    printf("List of Files & Folders:-\n");    for(d=readdir(dr); d!=NULL; d=readdir(dr)){       printf("%s\n", d->d_name);    }    closedir(dr); }

উদাহরণ

ডিরেক্টরিতে ফাইল এবং ফোল্ডার প্রিন্ট করার C প্রোগ্রাম:

#include<stdio.h> #include<conio.h> #include<dirent.h> int main() {    struct dirent *d;    DIR *dr;    dr = opendir(".");    if(dr!=NULL) {       printf("List of Files & Folders:-\n");       for(d=readdir(dr); d!=NULL; d=readdir(dr)) {          printf("%s\n", d->d_name);       }       closedir(dr);    }    else    printf("\nerror while opening the directory!");    getch();    return 0; }

আউটপুট

উপরোক্ত প্রোগ্রামটি এক্সিকিউট করলে নিচের আউটপুটটি দেখায়:

List of Files & Folders:- . .. accessing array.c accessing array.exe accessing array.o bhanu.txt C Programs convert 2 digit no into english word.c convert 2 digit no into english word.exe convert 2 digit no into english word.o DATA delete vowels in string.c delete vowels in string.exe delete vowels in string.o emp.txt EVEN ex.c ex.exe ex.o example pro.c example pro.exe example pro.o fibbinoci serie.c fibbinoci serie.exe fibbinoci serie.o file file example1.c file example1.exe file example1.o file example2.c file example2.exe file example2.o implicit conversion.c implicit conversion.exe implicit conversion.o leap year.c leap year.exe leap year.o little n big endian.c little n big endian.exe little n big endian.o work out examples

  1. Windows 11/10-এ ফাইল ও ফোল্ডার ডিলিট করার সব পদ্ধতি

  2. Firefox প্রোফাইল ফাইল এবং ফোল্ডার ব্যাখ্যা

  3. অ্যান্ড্রয়েডে ফাইল এবং ফোল্ডার লুকানোর উপায়

  4. অ্যান্ড্রয়েড স্মার্টফোনে ফাইল ও ফোল্ডার নিরাপদে লুকানোর পদ্ধতি