0% found this document useful (0 votes)
112 views7 pages

FILE ORGANIZATION - Single Level

The document describes a C program that implements a single-level directory file organization technique. The program allows users to insert, display, delete, and search files stored in a single directory. It creates functions to perform each operation and stores file metadata in a structure along with the directory name. The program is run, demonstrating adding three files, displaying the directory contents, deleting a file, searching for a file, and closing the program.

Uploaded by

Arjun Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views7 pages

FILE ORGANIZATION - Single Level

The document describes a C program that implements a single-level directory file organization technique. The program allows users to insert, display, delete, and search files stored in a single directory. It creates functions to perform each operation and stores file metadata in a structure along with the directory name. The program is run, demonstrating adding three files, displaying the directory contents, deleting a file, searching for a file, and closing the program.

Uploaded by

Arjun Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

EX NO:6a FILE ORGANIZATION TECHNIQUE

SINGLE LEVEL DIRECTORY


Aim:
To write a c program to implement file organization using single level file directory technique
Single level directory:
The simplest method is to have one big list of all the files on the disk. The entire system will
contain only one directory which is supposed to mention all the files present in the file system. The
directory contains one entry per each file present on the file system.

Algorithm:
1. Start the program and include all the necessary header files.
2. Create structures for the file and file directory and declare the necessary variables.
3. Create InsertFile() to create files in the directory.
4. Create DisplayFiles() to print the file names that are in the directory.
5. Create DeleteFile() to delete a file from the directory.
If the file is present , it will be deleted else no deletion occurs.
6. Create SearchFile() to search the file required from the directory.
If the file if present in the directory, the file position will be displayed
Else “the file is not found” will be displayed .
7. Enter the directory name dir.dirName
8. Choose a options to perform operation – insert, display, delete, search, exit.
9. Print the result
10. Stop

Program coding:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct file{
char fileName[15][20];
char dirName[10];
int fno;

};
struct file dir;
int i,n;
void InsertFile(){
printf("\n Enter the File name ");
scanf("%s",dir.fileName[dir.fno]);
dir.fno++;
}
void DisplayFiles(){
printf("\n\n\n\n");
printf("+------------------------+");
printf("\n Directorytfiles | \n");
printf("+------------------------+");
printf("\n %s",dir.dirName);
for(i=0;i<dir.fno;i++){
printf("\n \t\t%s",dir.fileName[i]);

}
printf("\n+------------------------+");
printf("\n\n\n\n");
}
void DeleteFile(){
char name[20];
printf("\n Enter the file to be deleted : ");
scanf("%s",name);
for(i=0;i<dir.fno;i++){
if(strcmp(dir.fileName[i],name)==0){
printf("%s is deleted \t",dir.fileName[i]);
strcpy(dir.fileName[i],dir.fileName[dir.fno-1]);
dir.fno--;
}
}
}
void SearchFile(){
char name[20];
int found=-1;
printf("\n Enter the file to be searched :");
scanf("%s",name);
for(i=0;i<dir.fno;i++){
if(strcmp(dir.fileName[i],name)==0){
printf("\n The File is found at position %d",i+1);
found=1;
break;
}
}
if(found==-1)
printf("\n the file is not found ");
}
int main(){
int op;
dir.fno=0;
printf("\n Enter the directory name : ");
scanf("%s",dir.dirName);
while(1){
printf("\n choose the option \n1:Insert a file \n2:Display Files
\n3:Delete File \n4:Search File \n5:Exit \n>>");
scanf("%d",&op);
switch(op){
case 1:InsertFile();
break;
case 2:DisplayFiles();
break;
case 3:DeleteFile();
break;
case 4:SearchFile();
break;

case 5:exit(0);
}

}
return 0;
}
Output:

Enter the directory name : MyFolder

choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>1

Enter the File name hello.txt

choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>1

Enter the File name new.c

choose the option


1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>1

Enter the File name last.txt

choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>2

+------------------------+

Directory files |

+------------------------+

MyFolder

hello.txt

new.c

last.txt

+------------------------+

choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File
5:Exit

>>4

Enter the file to be searched :new.c

The File is found at position 2

choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>3

Enter the file to be deleted : new.c

new.c is deleted

choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>2

+------------------------+

Directory files |

+------------------------+

MyFolder

hello.txt

last.txt

+------------------------+
choose the option

1:Insert a file

2:Display Files

3:Delete File

4:Search File

5:Exit

>>5

Result:
Thus the C program to implement single level directory technique was written, executed and
the output was verified

You might also like