123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
File Splitting & Merging Utility

--------------------------------------------------------------------------------

Description : Its a File Splitting & Merging Utility in 'C'.

Code:
#include<stdio.h>
#include<conio.h>
#include<sys/stat.h>

// Funtion prototype to split in Equal size
void split_equal(char *fname,long int pieces);
// Funtion prototype to split in size defined by the user
void split_size(char *fname, long int sp_size);
// Funtion prototype to merge the splitted file
void merge(char *o_fname, long int no_file);

/*Main Starts*/
void main()
{
int ch;
long int size,pieces,sp_size,no_file;
char *fname,*o_fname;
FILE *fp;
struct stat statbuff; // stat structure to get file size
clrscr();
printf("
SPLITTING PROCESS......");
printf("


Enter the path of the file to be splitted : ");
fflush(stdin);
gets(fname); // Name of the File to be splitted
fp=fopen(fname,"rb+");
if(fp==NULL)
{
printf(" ");
fprintf(stderr,"Cannot Open the File.");
getch();
exit(0);
}
stat(fname,&statbuff);
size=statbuff.st_size; // Get the size of the file to splitted
fclose(fp);
printf("

The Size of the File is %ld bytes.",size);
printf("

SELECT THE WAY IN WHICH TO SPLIT THE FILE : ");
printf("
1.) In Equal Numbers.");
printf("
2.) User Defined Sizes.");
printf("

Enter your choice : ");
scanf("%d",&ch);

// Start case
switch(ch)
{
case 1: printf("
Enter the Number of Pieces : ");
scanf("%ld",&pieces); // Define the number of pieces in which file
will
be splitted
if(pieces>size)
{
printf("
Invalid Number of pieces.");
getch();
exit(0);
}
split_equal(fname,pieces); // Function call to split
printf("
Files Successfully Splitted.");
getch();
break;

case 2: printf("
Enter the Size in which to split the files : ");
scanf("%ld",&sp_size); // Define the size in which file will be
splitted
if(sp_size>size)
{
printf("
Invalid size of the pieces.");
getch();
exit(0);
}
split_size(fname,sp_size); // Function call to split
printf("
Files Successfully Splitted.");
getch();
break;
default: printf("
Invalid Choice.");
getch();
exit(0);
} // End Case

printf("


A .bat file has been created, copy all the
pieces<BR>);
printf(" and the .bat file to the desired destination and run<BR>);
printf(" the .bat file to get the merged file.");
getch();

//The Merging Process

/* printf("
Do You Want to Merge the Splitted Files (Y/N): ");
fflush(stdin);
ch=getchar();
if(toupper(ch)=='Y')
{
// Start The Merging Process
clrscr();
printf("
MERGING PROCESS.......");
printf("


Enter the Path and Name of the Merged Output File : <BR>);
fflush(stdin);
gets(o_fname); // Get the name of Output file
printf("
Enter the Number of Files which are to be Merged : ");
scanf("%ld",&no_file); // Get the Number of splitted files to be
merged
merge(o_fname,no_file); // Function call for Merging the Files
printf("
The Splitted Files have been successfully Merged.");
getch();
} */
} // End Main

// Start of function definition split_equal
void split_equal(char *fname,long int pieces)
{
FILE *fp,*n_fp,*fp_bat;
char ch,*p,q[50],t[50],z[50];
int i,j,k,x;
char *n_fname,base[5];
long int size,f_size,offset;
struct stat statbuff;
stat(fname,&statbuff);
size=statbuff.st_size;
offset=size%pieces;
f_size=(size-offset)/pieces;
p=fname;
printf("
The first %ld files will be of size %ld bytes
each.",pieces-1,f_size);
printf("
The %ldth file will be of size %ld
bytes.<BR>,pieces,f_size+offset);
fp=fopen(fname,"rb+");
if(fp==NULL)
{
printf(" ");
fprintf(stderr,"Cannot Open the File.");
getch();
exit(0);
}
strrev(p);
for(j=0;p[j]!='\';j++) //Extracting the Name of file in variable q
{
q[j]=p[j];
}
q[j]='
 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG