Type Here to Get Search Results !

Program to simulate two level file organization technique

TWO LEVEL DIRECTORY

AIM: Program to simulate two level file organization technique

Description:

In the two-level directory system, each user has own user file directory (UFD). The system maintains a master block that has one entry for each user. This master block contains the addresses of the directory of the users. When a user job starts or a user logs in, the system's master file directory (MFD) is searched. When a user  refers to a particular file, only his own UFD is searched.

SOURCE CODE :


#include<stdio.h> struct

{

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

int fcnt;

}dir[10];


void main()

{

int i,ch,dcnt,k; char f[30], d[30]; 

clrscr();

dcnt=0;


while(1)

{

printf("\n\n1. Create Directory\t2. Create File\t3. Delete File"); 

printf("\n4. Search File\t\t5. Display\t6. Exit\t Enter your choice --"); 

scanf("%d",&ch);

switch(ch)

{

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

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

   dir[dcnt].fcnt=0;

   dcnt++;

   printf("Directory created"); break;

              case 2: 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",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++) 

  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]); 

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); 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);

}


}

getch();

}

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 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 – 6


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Featured post

M

M