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

📄 mouse01.cpp

📁 copy file auto
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <TIME.H>

#define MAXBUFSIZE 4096
#define MAXFILE 3

int copyfile(char *pdes,char *psou);
int creatfilename();
long getfiledate(char *pname);

char oldfilename[100];                  ///put the oldest file name
char newfilename[100];                  ///put the newest file name
char soufilename[100];                  ///put the source file name

long oldfiledate;                       ///put the date of oldest file
long newfiledate;                       ///put the date of newest file
long soufiledate;                       ///put the date of source file


void main()
{

	/////get the three filenames and filedates
	if(creatfilename()<0)
	{
		printf("file path woring!");
		return;
	}

//	printf("newdate=%d,file=%s\n",newfiledate,newfilename);
//	printf("olddate=%d,file=%s\n",oldfiledate,oldfilename);
//	printf("soudate=%d,file=%s\n",soufiledate,soufilename);

	//////////////////////////////////////////////////////
	//compare the two file to decide whether the source///
	//file has been updated///////////////////////////////
	//////////////////////////////////////////////////////
	if(soufiledate>newfiledate)
	{
		////has been updated
		copyfile(oldfilename,soufilename);
	}

	return;

}

/////get the three filenames and filedates
int creatfilename()
{
	long filedate[MAXFILE];

	char filename[100];

	int newfilenum;           //the NO of the newest file
	int oldfilenum;           //the NO of the oldest file


	///get the source filename and filedate
	sprintf(soufilename,"TuxedoNightlyBuildStatus.htm");
	if((soufiledate=getfiledate(soufilename))<0)
	{
		return -1;
	}

	///get the bak filedates
	for(int i=0;i<=MAXFILE-1;i++)
	{
		sprintf(filename,"../TuxedoNightlyBuildStatus%d.htm",i);

		if((filedate[i]=getfiledate(filename))<0)
		{
			return -1;
		}

	}


	//find the newest file NO and get the date	
	for( i=0;i<=MAXFILE-2;i++)
	{
		if(i==0)
		{
			if(filedate[i]>filedate[i+1])
			{
				newfiledate=filedate[0];
				newfilenum=0;
			}
			else
			{
				newfiledate=filedate[1];
				newfilenum=1;
			}

		}
		else
		{
			if(filedate[i+1]>=newfiledate)
			{
				newfiledate=filedate[i+1];
				newfilenum=i+1;
			}

		}

	}
	
	//find the oldest file NO and get the date	
	for(i=0;i<=MAXFILE-2;i++)
	{
		if(i==0)
		{
			if(filedate[i]<=filedate[i+1])
			{
				oldfiledate=filedate[0];
				oldfilenum=0;
			}
			else
			{
				oldfiledate=filedate[1];
				oldfilenum=1;
			}

		}
		else
		{
			if(filedate[i+1]<oldfiledate)
			{
				oldfiledate=filedate[i+1];
				oldfilenum=i+1;
			}

		}

	}

	///get the newest and oldest filename
	sprintf(newfilename,"../TuxedoNightlyBuildStatus%d.htm",newfilenum);
	sprintf(oldfilename,"../TuxedoNightlyBuildStatus%d.htm",oldfilenum);

	return 1;
}



///get the date in a file 
long getfiledate(char *pname)
{
	FILE* pfile;
	char buf;
	char buffer[10];
	int byteread;
	char cdate[10];   ////date as char
	long ddate=0;     ////date as long int
	int tmp=1;
	int offset;       //bytes of the date offset its standard location

	if ((pfile=fopen(pname,"r"))==NULL)
	{
		if((pfile=fopen(pname,"w+"))==NULL)
		{
			return -1;
		}
		
		return 0;
	}
    else
	{
		do
		{
			if((byteread=fread(&buf, 1,1,pfile))==0)
			{
				return 0;
			}
			else
			{
				
				////find the "DATE" in the file
				switch (tmp)
				{
				case 1:
					if(buf=='D')
					{
						tmp++;
					}
					break;
				case 2:
					if(buf=='A')
					{
						tmp++;
					}
					else
					{
						tmp=1;
					}
					break;
				case 3:
					if(buf=='T')
					{
						tmp++;
					}
					else
					{
						tmp=1;
					}
					break;
				case 4:
					if(buf=='E')
					{
						tmp++;
					}
					else
					{
						tmp=1;
					}
					break;
				case 5:
					if(buf==':')
					{
						tmp++;
					}
					else
					{
						tmp=1;
					}
				}
			}

		}
		while(tmp<=5);


     ///get the string behind the DATE,put into the buffer
		for(int i=0;i<=9;i++)
		{
			byteread=fread(&buf,1,1,pfile);
			buffer[i]=buf;
		}

		if(buffer[2]=='/')
		{
			offset=-1;
		}
		else
		{
			if(buffer[3]=='/')
			{
				offset=0;
			}
			else
			{
				if(buffer[4]=='/')
				{
				offset=1;
				}
				else
				{
					printf("there are wrong date in this file!\n");
					return 0;
				}
			}
		}

     ///put the date in the cdata as char
		cdate[2]=buffer[1+offset];
		cdate[3]=buffer[2+offset];
		cdate[4]=buffer[4+offset];
		cdate[5]=buffer[5+offset];
		cdate[0]=buffer[7+offset];
		cdate[1]=buffer[8+offset];
		cdate[6]=0;


		///convert the date from char to long int
		for(i=0;i<=5;i++)
		{
			int tmp=1;
			for(int k=0;k<=4-i;k++)
			{
				tmp*=10;
			}
			ddate+=(cdate[i]-48)*tmp;
		}

		fclose(pfile);

		return ddate;
		
	}

}


///copy psou(source) file to pdes(destine) file
int copyfile(char *pdes,char *psou)
{
    FILE *pdfile;
    FILE *psfile;
	char buffer[MAXBUFSIZE];
	int byteread;


    if ((psfile=fopen(psou,"r"))==NULL)
	{
         return -1;
	}
    else
	{

		 if ((pdfile=fopen(pdes,"w"))==NULL)
		 {
			 return -1;
		 }

		 do
		 {

			 byteread = fread(buffer, 1,MAXBUFSIZE,psfile);
			 fwrite(buffer, 1,byteread,pdfile);

		 }
		 while (byteread > 0);   

		 fclose(pdfile);
		 fclose(psfile);

	}

	return 1;
}

⌨️ 快捷键说明

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