www.pudn.com > cghost.rar > XCOPY.C
#include#include #include #include #include #include #include #include void copy(void); void copyaction(void); int bufcopy(char fromname[13],char toname[MAXPATH]); char searchstr[MAXPATH],newpath[MAXPATH],newname[MAXPATH], drive[MAXPATH],subdir[MAXPATH],pathname[MAXPATH], file[MAXFILE],ext[MAXEXT],oldname[MAXPATH]; int done,problem,answer,count; unsigned char *buffer; struct ffblk dta; main(int argc,char *argv[]) { buffer=(unsigned char *) calloc(32767,1); if(buffer==NULL) { printf("\Not enough memory to run this utility get rid of"); printf("\nmemory resident programs and try again.\n"); exit(1); } if(argc>2) { strcpy(searchstr,argv[1]); fnsplit(searchstr,drive,subdir,file,ext); sprintf(pathname,"%s%s",drive,subdir); strcpy(newpath,argv[2]); count=strlen(newpath); if(newpath[count-1]!=92) { newpath[count]=92; newpath[count+1]=0; } } else { printf("usage: vcopy [filespec topath]\n"); free(buffer); exit(2); } copy(); free(buffer); return(0); } void copy(void) { count=0; done=findfirst(searchstr,&dta,47); while(!done) { strcpy(oldname,pathname); strcat(oldname,dta.ff_name); strupr(oldname); strcpy(newname,newpath); strcat(newname,dta.ff_name); strupr(newname); copyaction(); done=findnext(&dta); } if(count>0) printf("\nNumber of files copied %3d\n",count); else printf("\nNo files copied\n"); } void copyaction(void) { printf("copy %-12s ",oldname); problem=bufcopy(oldname,newname); if(!problem) { printf("-copied to %s.\n",newname); count++; } else printf("-not copied .ERROR!\n"); } int bufcopy(char fromname[MAXPATH],char toname[MAXPATH]) { long size,numread,filepos; int numtoget; FILE *fromfile,*tofile; int inhandle,outhandle; fromfile=fopen(fromname,"r"); tofile=fopen(toname,"w"); if(tofile==NULL||fromfile==NULL) return(1); inhandle=fileno(fromfile); outhandle=fileno(tofile); size=filelength(inhandle); if(size<=32767) numtoget=size; else numtoget=32767; numread=0; do { filepos=ftell(fromfile); fseek(fromfile,numread,0); _read(inhandle,buffer,numtoget); numread+=numtoget; fseek(tofile,filepos,0); _write(outhandle,buffer,numtoget); if(numread+numtoget>size) numtoget=size-numread; }while(numtoget!=0); fclose(fromfile); fclose(tofile); return(0); }