Add to Favorites    Make Home Page 14406 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Data Structures Home » Files and Folders using Data structure.

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Files and Folders using Data structure.
Author Meenakshisundaram.M
Author Email sundaram_80 [at] yahoo.com
Description Hi, This is my attempt to use Data structure concept(linked
list through pointers) to interact with files and folders.
This program uses simple concepts in C for storing and displaying all
files and folders from the current directory.
Note :
" struct ffblk " is a predefined structure that enables u to view files
and folders from your current directory.
Hope, you may get something useful from this program(especially in how to
assign pointer variables).
Category C++ » Data Structures
Hits 386198
Code Select and Copy the Code
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<conio.h> #include<dir.h> #include<dos.h> struct node { char *name; /* used to get file / folder name. */ int attrib; /* used to get it's attribute. */ struct node *next; /* concept of Linked list */ }; void main() { struct node *head,*head1; struct node *list,*list1; struct node * place(struct ffblk ff,struct node *first,int don); void display(struct node *first); void print(struct node *list,int *i); int i,c,c1,done,done1; struct ffblk f,f1; head=NULL; head1=NULL; clrscr(); done=findfirst("*.*",&f,FA_DIREC|FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH); /* struct variable "f" contains all files and folders information */ done1=findfirst("*.*",&f1,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH); /* struct variable "f1" contains all files information */ head=place(f,head,done); /* content of f is placed in struct head */ display(head); /* Note : f contains name of files and folders with their attributes in f.ff_name, f.ff_attrib which is assigned to name, attrib in the struct node */ printf(" ************************************************* "); getch(); head1=place(f1,head1,done1); /* content of f1 is placed in struct head1 */ display(head1); /* Note : f1 contains name of files and folders with their attributes in f1.ff_name, f1.ff_attrib which is assigned to name, attrib in the struct node */ printf(" ************************************************* "); getch(); i=0; c1=0; /* Here, head and head1 are compared so that we could extract only the folders. */ list=head; /* head is assigned to list */ while(list!=NULL) { list1=head1; /* head1 is assigned to list1 */ if(list1==NULL) /* if there are 0 files */ print(list,&i); /* then display content of list */ else { while(list1!=NULL) { if(strcmp(list->name,list1->name)==0) /* compare list and list1 */ c1=1; list1=list1->next; } if(c1==0) /* if folder found both in list and list1*/ print(list,&i); /* then display content of list */ } c1=0; list=list->next; } printf(" FOLDERS = %d",i); printf(" ************************************************* "); printf(" Where,"); printf(" H - Hidden"); printf(" D - Directory"); printf(" R - Read only"); printf(" S - System"); printf(" A - Archive"); getch(); free(list1); free(list); free(head); free(head1); } void print(struct node *list,int *i) { void property(struct node *list); /* to display folders other than default folders (. and ..) */ if((strcmp(list->name,"."))!=0 && (strcmp(list->name,".."))!=0) { *i=*i+1; /* counts number of folders */ property(list); printf(" %s ",list->name); } } void property(struct node *list) { /* finds their attribute */ if(list->attrib & FA_HIDDEN) printf("(H)"); if(list->attrib & FA_DIREC) printf("(D)"); if(list->attrib & FA_RDONLY) printf("(R)"); if(list->attrib & FA_SYSTEM) printf("(S)"); if(list->attrib & FA_ARCH) printf("(A)"); } struct node * place(struct ffblk ff,struct node *first,int don) { static int j; void create(struct node *first,char *ch,int d); void insert(struct node *first,char *ch,int d); int i=0,c=0; char *p; if(don!=0) first=NULL; else { while(don==0) { if(i==0) { first=(struct node *)malloc(sizeof(struct node)); if ((p = (char *) malloc(14)) == NULL) exit(1); strcpy(p,ff.ff_name); create(first,p,ff.ff_attrib); i=1; } else { if ((p = (char *) malloc(14)) == NULL) exit(1); strcpy(p,ff.ff_name); insert(first,p,ff.ff_attrib); } don=findnext(&ff); c=c+1; } } if(j==0) { printf(" ************************************************* "); printf(" %d FILES & FOLDERS ",c); j+=1; } else printf(" %d FILES ",c); return(first); } void create(struct node *first,char *ch,int d) { char *p; if ((p = (char *) malloc(sizeof(ch))) == NULL) exit(1); p=ch; first->name=p; first->attrib=d; first->next=NULL; return; } void insert(struct node *first,char *ch,int d) { struct node *temp,*list; char *p; list=first; while(list->next!=NULL) list=list->next; if ((p = (char *)malloc(sizeof(ch))) == NULL) exit(1); p=ch; temp=(struct node *)malloc(sizeof(struct node)); temp->name=p; temp->attrib=d; temp->next=NULL; list->next=temp; return; } void display(struct node *first) { struct node *list; void property(struct node *list); list=first; if(list==NULL) printf(" NULL"); else { while(list->next!=NULL) { property(list); printf("%s %d ",list->name,list->attrib); list=list->next; } property(list); printf("%s %d ",list->name,list->attrib); } return; }

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=493


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review