您的位置:首页 > 编程语言 > C语言/C++

一个C++程序上传文件到百度云的实例

2017-03-21 19:02 393 查看
功能:获得当前执行文件路径,并将该路径下的文件,通过bypy上传到百度云端,云端文件夹以上传时间命名(如:201703211849)

注意:本程序使用了百度云Python客户端bypy,请按照并配置好bypy

程序来如下:

{
//活动当前执行文件路径,存于SaveResult内
char szModuleFilePath[MAX_PATH];
char SaveResult[MAX_PATH];
int n = GetModuleFileNameA(0, szModuleFilePath, MAX_PATH); //获得当前执行文件的路径
szModuleFilePath[ strrchr(szModuleFilePath, '\\') - szModuleFilePath + 1 ] = 0;//将最后一个"\\"后的字符置为0
strcpy(SaveResult,szModuleFilePath);
printf("%s\n", SaveResult);
//得到当前时间(s),存于now_time (char型)
time_t now_time_t;
now_time_t=time(NULL);
static char now_time[16];
struct tm*ptm = localtime(&now_time_t);
strftime(now_time, sizeof(now_time), "%Y%m%d%H%M%S", ptm) ;
cout <<now_time<<endl;

string commend_string = "bypy -v upload " +  string(szModuleFilePath) + " /" + now_time;//合成上传命令
cout<<commend_string.c_str()<<endl;
char commend[MAX_PATH];
strcpy(commend,commend_string.c_str());

system(commend);//调用bypy进行上传
return 1;
}


说明:当前路径存于:SaveResult  (char型);当前时间存于now_time (char型)
执行效果



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息