比这种简单的纯C写法?
程序代码:
//------------------------------------------------------------------------------------------------------------------//
int main(int argc, char* argv[])
{
int i=0, j=0, k=0, len=0, opt=0;
char *ex, *config=0;
char FN[256];
char PathArr[256];
char FilePath[256]={0};
char wFilePath[256]={0};
char eFilePath[256]={0};
char FileName[1024]={0};
//time_t ltime;
char cpDate[25]={0};
char cpTime[25]={0};
char cpFilename[50]={0};
//time( <ime );
argc=3;argv[1]="3";argv[2]="C:\\STDF\\33\\AAA_BBBBBB_CCC_DDDDD_00_02_120215180213.std";
opt=atoi(argv[1]); //因為0:執行檔名稱 1:選擇參數 2:檔案路徑
_strtime( cpTime );
_strdate( cpDate );
strncpy(cpFilename, cpDate+6,2);
strncpy(cpFilename+2, cpDate,2);
strncpy(cpFilename+4, cpDate+3,2);
strncpy(cpFilename+6, cpTime,2);
strncpy(cpFilename+8, cpTime+3,2);
strncpy(cpFilename+10, cpTime+6,2);
time_t unixtime=0;
time(&unixtime);
strcpy(PathArr, argv[2]);
printf("\nThe Path is %d: %s\n\n",opt,PathArr);
printf("1:STDF Transform ATDF.\n2:ATDF Transform STDF(No Finish).\n3:STDF Merge STDF.\n4.ATDF Merge ATDF(No Finish).\n");
strcpy(FN,PathArr);
ex=strrchr(PathArr,'.');
int nIndex =strlen(PathArr) -sizeof ("100603194915.std");
PathArr[nIndex +1] ='*';
PathArr[nIndex +2] ='.';
PathArr[nIndex +3] ='s';
PathArr[nIndex +4] ='t';
PathArr[nIndex +5] ='d';
PathArr[nIndex +6] ='\0';
for(i=0;i<sizeof(PathArr);i++)
{
if (PathArr[i]=='\\')
j=i;
}
for(i=sizeof(PathArr);i>=0;i--)
{
if (PathArr[i]=='\0')
k=i;
}
memcpy( FilePath, PathArr, j+1 );
strncpy( FileName,PathArr+j+1,k-j );
nIndex =strlen(FileName);
FileName[nIndex -5] ='\0';
strcat(FileName,cpFilename);
memcpy(wFilePath, FilePath, strlen(FilePath));
nIndex =strlen(wFilePath);
wFilePath[nIndex ] ='T';
wFilePath[nIndex +1] ='r';
wFilePath[nIndex +2] ='a';
wFilePath[nIndex +3] ='n';
wFilePath[nIndex +4] ='s';
wFilePath[nIndex +5] ='f';
wFilePath[nIndex +6] ='o';
wFilePath[nIndex +7] ='r';
wFilePath[nIndex +8] ='m';
wFilePath[nIndex +9] ='\\';
if( (_access(wFilePath, 0 )) == -1 )
int intRet = (_mkdir(wFilePath));
strcat(wFilePath,FileName);
strcpy(eFilePath, wFilePath);
nIndex =strlen(wFilePath);
wFilePath[nIndex ] ='.';
wFilePath[nIndex +1] ='a';
wFilePath[nIndex +2] ='t';
wFilePath[nIndex +3] ='d';
wFilePath[nIndex +4] ='f';
wFilePath[nIndex +5] ='\0';
nIndex =strlen(eFilePath);
eFilePath[nIndex ] ='.';
eFilePath[nIndex +1] ='l';
eFilePath[nIndex +2] ='o';
eFilePath[nIndex +3] ='g';
eFilePath[nIndex +4] ='\0';
len=strlen(ex);
if((opt==1)&&(len==4))
ST2AT(1,FN,wFilePath,eFilePath);
else if((opt==2)&&(len==5))
AT2ST(2,FN,wFilePath,eFilePath);
else if((opt==3)&&(len==4))
ST2MG(3,FN,wFilePath,eFilePath);
else if((opt==4)&&(len==5))
AT2MG(4,FN,wFilePath,eFilePath);
else
printf("opt Number Input Error!");
printf("Work Finish !!!");
//system("pause");
return 0;
}