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

File Management System

This C++ program implements a basic file management system with functions to create, delete, and view files. It uses structures to store file metadata like name, extension, and index pointers. File data is stored in a global array using a linked list approach with each element pointing to the next. The main function provides a menu to test the create, delete, and view file capabilities of the class.

Uploaded by

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

File Management System

This C++ program implements a basic file management system with functions to create, delete, and view files. It uses structures to store file metadata like name, extension, and index pointers. File data is stored in a global array using a linked list approach with each element pointing to the next. The main function provides a menu to test the create, delete, and view file capabilities of the class.

Uploaded by

Hamza Aziz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

File Management System

#include<iostream>

#include <string.h>

using namespace std;

struct FData{

char data;

int nextIndex;

};

struct File{

string fileName;

string fileExt;

int start;

int fileIndex;

};

class FileManagement

private:

FData fileData[500];

File Fileinfo[50];

public:

FileManagement()

for(int i =0 ; i<500;i++)

fileData[i].nextIndex=-1;

fileData[499].nextIndex=-3;

for(int i =0 ; i<50;i++)

Fileinfo[i].fileIndex=-1;

}
Fileinfo[49].fileIndex=-3;

void createFile(string fName,string Ext,char filedata[])

int i,k,n=0,y=0,j;

int lenght=strlen(filedata);

while(fileData[i].nextIndex!=-1)

i++;

cout<<"\n";

while(Fileinfo[j].fileIndex!=-1)

j++;

Fileinfo[j].start=i;

Fileinfo[j].fileIndex=j;

Fileinfo[j].fileName=fName;

Fileinfo[j].fileExt=Ext;

n=i;

while(y<lenght)

fileData[n].data=filedata[k];

fileData[n].nextIndex=n;

n++;

y++;

k++;

fileData[n].nextIndex=-2;

}
bool deleteFile(string fName,string ext)

int n=0;

int start=-1;

int j=0 ;

while(Fileinfo[n].fileIndex!=-1)

if((Fileinfo[n].fileName==fName)&&
(Fileinfo[n].fileExt==ext))

start=Fileinfo[n].start;

Fileinfo[n].fileIndex=-1;

n++;

if(start!=-1)

for(int i = start ; fileData[i].nextIndex!=-2;i++)

fileData[i].nextIndex=-1;

return true;

else

return false;

bool viewFile(string Fname,string ext)


{

int n=0;

int start=-1;

int j=0 ;

while(Fileinfo[n].fileIndex!=-1)

if((Fileinfo[n].fileName==Fname)&&
(Fileinfo[n].fileExt==ext))

start=Fileinfo[n].start;

n++;

if(start!=-1)

cout<<"Data:\n";

for(int i = start ; fileData[i].nextIndex!=-2;i++)

cout<<fileData[fileData[i].nextIndex].data<<"";

return true;

else

return false;

};

int main()

{
int i, opt = 1;

int num;

FileManagement file;

string fName;

string Ext;

char fileData[100];

while (opt != 0)

cout << "\n\n\t 1: Create File. ";

cout << "\n\n\t 2: Delete File. ";

cout << "\n\n\t 3: View File ";

cout << "\n\n\t 0: Exit. ";

cout << "\n\n\t Enter Your Choice... ";

cin >> opt;

switch(opt)

case 1:

cout<<"Enter File Name\n";

cin>>fName;

cout<<"Enter File Extension\n";

cin>>Ext;

cout<<"Enter File data\n";

cin>>fileData;

file.createFile(fName,Ext,fileData);

break;

case 2:

cout<<"Enter File Name\n";

cin>>fName;

cout<<"Enter File Extension\n";

cin>>Ext;
if(file.deleteFile(fName,Ext))

cout<<"File Deleted Succesfully";

else

cout<<"File not found: File Deletion Unsucessful";

break;

case 3:

cout<<"Enter File Name\n";

cin>>fName;

cout<<"Enter File Extension\n";

cin>>Ext;

if(file.viewFile(fName,Ext))

cout<<"\nFile Viewed Successfully";

else

cout<<"\nFile Not Found";

break;

You might also like