开发工具:
文件大小: 299kb
下载次数: 0
上传时间: 2008-09-05
详细说明:
c语言常用算法 fcopy #include #include #include #include #include #include #include #include main(int argc,char *argv[]) { int copy(char *,char *); char searchstr[MAXPATH],newpath[MAXPATH]; if(argc>2) { strcpy(searchstr,argv[1]); strcpy(newpath,argv[2]); } else { printf("usage: vcopy [filespec topath]\n"); exit(2); } copy(searchstr,newpath); return(0); } int copy(char searchs tr[],char newpath[]) { int bufcopy(char fromname[13],char toname[MAXPATH]); char newname[MAXPATH], drive[MAXPATH],subdir[MAXPATH],pathname[MAXPATH], file[MAXFILE],ext[MAXEXT],oldname[MAXPATH]; int done,problem,count; struct ffblk dta; fnsplit(searchstr,drive,subdir,file,ext); sprintf(pathname,"%s%s",drive,subdir); if(chdir(newpath)) /*not exist this dir*/ { if(mkdir(newpath)) { printf("\nfaile to make newparh\n"); return 0; } else printf("\nsuccess to make newpath\n"); getch(); } else chdir(".."); count=strlen(newpath); if(newpath[count-1]!=92) { newpath[count]=92; newpath[count+1]=0; } 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();*/ printf("copy %-12s ",oldname); problem=bufcopy(oldname,newname); if(!problem) { printf("-copied to %s.\n",newname); count++; } else printf("-not copied .ERROR!\n"); done=findnext(&dta); } if(count>0) printf("\nNumber of files copied %3d\n",count); else printf("\nNo files copied\n"); return 1; } int bufcopy(char fromname[MAXPATH],char toname[MAXPATH]) { unsigned char *buffer; 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; 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"); return 1; } 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); free(buffer); return(0); } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.