⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcopy.c

📁 c语言和c++的编程思想和c语言编程中常用的一些算法的代码
💻 C
字号:
#include <stdio.h>
#include <alloc.h>
#include <dir.h>
#include <string.h>
#include <io.h>
#include <conio.h>
#include <process.h>
#include <ctype.h>

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);
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -