c++builder 读取文件,提取绝对路径,提取文件名 函数应用实例

#pragma hdrstop
#pragma argsused


#include "windows.h"
#include "usbprt.h"
#include "burning.h"
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <Mergemod.h>
//#include <string.h>


int _tmain(int argc, _TCHAR* argv[])
{
unsigned int i=0,j=0,k=0,Num=0,write_mode=0;
int size=0,ret=0;
unsigned long  result=0;
unsigned long  addr=0;
unsigned long  times=0;
unsigned long  last_bytes=0;
unsigned long  sectors=0;
HANDLE m_hDev = NULL;
unsigned char bin_buffer[1024*64]={};
unsigned char ram_buffer[1024*4]={};
unsigned char buffer[2]={0,0};
unsigned char mcu_type = 0;
char exeFullPath[MAX_PATH + 1]; // Full path
char test_bin[] = "\\test.bin";
unsigned long flashaddress =0;
unsigned long activetime[2]={0,0};
char FilePath[100] = {0};
//strncpy(FilePath,"\\drive_bin\\dut_5315_flash_v01b9.bin",sizeof("\\drive_bin\\dut_5315_flash_v01b9.bin"));
//printf("%s test\n",FilePath);
//return 0;
if(argc < 3)
{
printf("\tNo bin Parameter !\n");
//getchar();
return 0;
}
if(argc < 5)
{
flashaddress = 0x00;
}
else
{
flashaddress = strtol(argv[4],NULL,16);
}
//flashaddress = strtol(argv[4],NULL,16);
//printf("%x,%s,%s,%s,%s,%s,%s,0x%x\n",argc,argv[0],argv[1],argv[2],argv[3],argv[4],argv[5],flashaddress);///显示参数
if(!strcmp(argv[3],"usb"))
{
write_mode = 1;          //write the usb mode .
} else if(!strcmp(argv[3],"evk"))
{
write_mode = 4;         //write the dut via sws .
}
else
{
printf("\tThe download mode error ! --> Please set \"usb\" or \"evk\" .\n");
return 0;
}
if(!strcmp(argv[1],"8266") || !strcmp(argv[1],"8267") || !strcmp(argv[1],"8366") || !strcmp(argv[1],"8368")){
mcu_type = 2;
}
else if(!strcmp(argv[1],"5562")){
mcu_type = 1;
}
else{
printf("\t Please select the approptiate \' mcu \'\n");
return 0;
}


GetModuleFileName(NULL,exeFullPath,MAX_PATH);  //get the absolute path
(strrchr(exeFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串 (strrchr(exeFullPath, '\\'))[1]   获得文件名  

//strcat(exeFullPath,test_bin);
//printf("\t%s,%d\n",exeFullPath,write_mode);
if(!strcmp(argv[1],"8266"))
{
//strncpy(FilePath,"\\drive_bin\\dut_5325_flash_v0222.bin",sizeof("\\drive_bin\\dut_5325_flash_v0222.bin"));
strcat(exeFullPath,"\\drive_bin\\dut_5325_flash_v0222.bin");
}
if(!strcmp(argv[1],"8267"))
{
//strncpy(FilePath,"drive_bin\dut_8267_flash_v0002.bin",sizeof("drive_bin\\dut_8267_flash_v0002.bin"));
strcat(exeFullPath,"\\drive_bin\\dut_8267_flash_v0002.bin");
}
if(!strcmp(argv[1],"8366"))
{
//strncpy(FilePath,"\\drive_bin\\dut_5315_flash_v01b9.bin",sizeof("\\drive_bin\\dut_5315_flash_v01b9.bin"));
strcat(exeFullPath,"\\drive_bin\\dut_5315_flash_v01b9.bin");
}
if(!strcmp(argv[1],"8368"))
{
//strncpy(FilePath,"\\drive_bin\\dut_5318_flash_v020a.bin",sizeof("\\drive_bin\\dut_5318_flash_v020a.bin"));
strcat(exeFullPath,"\\drive_bin\\dut_5318_flash_v020a.bin");
}
if(!strcmp(argv[1],"5562"))
{
strcat(exeFullPath,"\\drive_bin\\dut_5560_flash.bin");
}
//m_hDev = GetPrintDeviceHandle(0xffff);
if(mcu_type == 1 && write_mode ==1){
m_hDev = GetPrintDeviceHandle2(0xffff);
}
else{
m_hDev = GetPrintDeviceHandle(0xffff);
}
if(write_mode ==4){
if(mcu_type == 1){
bu
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值