Program-8 - File Organization Techniques
Program-8 - File Organization Techniques
Program 8: Simulate following File Organization Techniques a) Single level directory b) Two level directory
A directory is a container that is used to contain folders and files. It organizes files and folders in a
hierarchical manner.
Just like we use folders to keep your papers and documents in order, the operating system uses
directories to keep track of files and where they are stored.
Different structures of directories can be used to organize these files, making it easier to find and
manage them.
1. Single-Level Directory
The single-level directory is the simplest directory structure. In it, all files are contained in the
same directory which makes it easy to support and understand.
2. Two-Level Directory
In the two-level directory structure, each user has their own user files directory (UFD).
The UFDs have similar structures, but each lists only the files of a single user.
System’s master file directory (MFD) is searched whenever a new user id is created.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch; char f[30];
dir.fcnt = 0;
printf("\nEnter name of directory: ");
scanf("%s", dir.dname);
while(1)
{
printf("\n\n1. Create File\t2. Delete File\t3. Search File \t 4. Display Files\t5. Exit\n
Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter the name of the file -- ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2: printf("\nEnter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f, dir.fname[i])==0)
{
printf("File %s is deleted ",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
}
}
if(i==dir.fcnt)
printf("File %s not found",f);
else
dir.fcnt--;
break;
case 3: printf("\nEnter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
}
break;
default: exit(0);
}
}
}
Sample Output:
Sample output
Directory Files
cse c1 c2
ds d1
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit
Enter your choice---4