0% found this document useful (0 votes)
247 views

Aim: To Perform A C Program To Execute Two Level Directory

The document describes implementing a two-level directory using C programming. It involves creating directories and files, deleting files, searching for files, and displaying the directory structure. The program uses structures to store directory and file names. It provides menus to perform operations and uses functions like strcmp to compare strings for matching directory and file names. Sample inputs and outputs are given to demonstrate the working of the program.

Uploaded by

dillip murali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
247 views

Aim: To Perform A C Program To Execute Two Level Directory

The document describes implementing a two-level directory using C programming. It involves creating directories and files, deleting files, searching for files, and displaying the directory structure. The program uses structures to store directory and file names. It provides menus to perform operations and uses functions like strcmp to compare strings for matching directory and file names. Sample inputs and outputs are given to demonstrate the working of the program.

Uploaded by

dillip murali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

IMPLEMENTATION OF TWO LEVEL DIRECTORY

AIM:

To perform a c program to execute Two level directory.

ALGORITHM:

Step 1:Start

Step 2: Initialize values gd=DETECT,gm,count,i,j,mid,cir_x;

Initialize character array fname[10][20];

Step 3: Initialize graph function as

Initgraph(& gd, &gm," c:/tc/bgi");

Clear device();

Step 4:set back ground color with setbkcolor();

Step 5:read number of files in variable count.

Step 6:if check i<count

Step 7: for i=0 & i<count

i increment;

Cleardevice();

setbkcolor(GREEN);

read file name;

setfillstyle(1,MAGENTA);

Step 8: mid=640/count;

REG NO: 190801001 PAGE NO:


EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

cir_x=mid/3;

bar3d(270,100,370,150,0,0);

settextstyle(2,0,4);

settextstyle(1,1);

outtextxy(320,125,"rootdirectory");

setcolor(BLUE);

i++;

Step 9:for j=0&&j<=i&&cir_x+=mid

j increment;

line(320,150,cir_x,250);

fillellipse(cir_x,250,30,30);

outtextxy(cir_x,250,fname[i]);

Step 10: End

PROGRAM:

#include<stdio.h>

struct

char dname[10],fname[10][10];

int fcnt;

}dir[10];

void main()

{
REG NO: 190801001 PAGE NO:
EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

int i,ch,dcnt,k;

char f[30], d[30];

clrscr();

dcnt=0;

while(1)

printf("\n\n 1. Create Directory\t 2. Create File\t 3. Delete File");

printf("\n 4. Search File \t \t 5. Display \t 6. Exit \t Enter your choice -- ");

scanf("%d",&ch);

switch(ch)

case 1: printf("\n Enter name of directory -- ");

scanf("%s", dir[dcnt].dname);

dir[dcnt].fcnt=0;

dcnt++;

printf("Directory created");

break;

case 2: printf("\n Enter name of the directory -- ");

scanf("%s",d);

for(i=0;i<dcnt;i++)

if(strcmp(d,dir[i].dname)==0)

printf("Enter name of the file -- ");


REG NO: 190801001 PAGE NO:
EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

scanf("%s",dir[i].fname[dir[i].fcnt]);

dir[i].fcnt++;

printf("File created");

break;

if(i==dcnt)

printf("Directory %s not found",d);

break;

case 3: printf("\nEnter name of the directory -- ");

scanf("%s",d);

for(i=0;i<dcnt;i++)

if(strcmp(d,dir[i].dname)==0)

printf("Enter name of the file -- ");

scanf("%s",f);

for(k=0;k<dir[i].fcnt;k++)

if(strcmp(f, dir[i].fname[k])==0)

printf("File %s is deleted ",f);

dir[i].fcnt--;

strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
REG NO: 190801001 PAGE NO:
EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

goto jmp;

printf("File %s not found",f);

goto jmp;

printf("Directory %s not found",d);

jmp : break;

case 4: printf("\nEnter name of the directory -- ");

scanf("%s",d);

for(i=0;i<dcnt;i++)

if(strcmp(d,dir[i].dname)==0)

printf("Enter the name of the file -- ");

scanf("%s",f);

for(k=0;k<dir[i].fcnt;k++)

if(strcmp(f, dir[i].fname[k])==0)

printf("File %s is found ",f);


REG NO: 190801001 PAGE NO:
EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

goto jmp1;

printf("File %s not found",f);

goto jmp1;

printf("Directory %s not found",d);

jmp1: break;

case 5: if(dcnt==0)

printf("\nNo Directory's ");

else

printf("\nDirectory\tFiles");

for(i=0;i<dcnt;i++)

printf("\n%s\t\t",dir[i].dname);

for(k=0;k<dir[i].fcnt;k++)

printf("\t%s",dir[i].fname[k]);

break;

default:exit(0);
REG NO: 190801001 PAGE NO:
EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

getch();

SAMPLE INPUT/OUTPUT:

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 1

Enter name of directory -- DIR1

Directory created

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 1

Enter name of directory -- DIR2

Directory created

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 2

REG NO: 190801001 PAGE NO:


EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

Enter name of the directory – DIR1

Enter name of the file -- A1

File created

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 2

Enter name of the directory – DIR1

Enter name of the file -- A2

File created

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 2

Enter name of the directory – DIR2

Enter name of the file -- B1

File created

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 5

Directory Files

DIR1 A1 A2

DIR2 B1
REG NO: 190801001 PAGE NO:
EX NO : 7 B IT18412 OPERATING SYSTEM CONCEPTS LABORATORY DATE:08/09/21

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 4

Enter name of the directory – DIR

Directory not found

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice -- 3

Enter name of the directory – DIR1

Enter name of the file -- A2

File A2 is deleted

1. Create Directory 2. Create File 3. Delete File

4. Search File 5. Display 6. Exit Enter your choice – 6

RESULT:
Thus implementation of Two level directory is implemented successfully.

REG NO: 190801001 PAGE NO:

You might also like