在给定的路径下建立2级目录,第一个目录是输入字符串的ID号,第二级目标是系统时间
#include <sys/stat.h>
#include <sys/types.h>
#include<stdio.h>
#include<time.h>
#include <iostream>
#include <string.h>
#include <sstream>
int main()
{
//获取当前时间的函数
time_t nowtime;
struct tm *timeinfo;
time(&nowtime);
timeinfo=localtime(&nowtime);
int year,month,day,hour,min,sec;
year=timeinfo->tm_year+1900;
month=timeinfo->tm_mon+1;
day=timeinfo->tm_mday;
hour=timeinfo->tm_hour;
min=timeinfo->tm_min;
sec=timeinfo->tm_sec;
char label1[10],label2[10];
memset(label1,0,sizeof(label1));
memset(label2,0,sizeof(label2));
sprintf(label1,"%4d%02d%02d",year,month,day);
sprintf(label2,"%02d%02d%02d",hour,min,sec);
cout<<label1<<endl;
cout<<label2<<endl;
string inputName;
inputName="rtsp://11.85.188.24:554/RTStream/cam16499_url2_copy.sdp";
string label,ID,camID;
label=strrchr(inputName.c_str(),'/'); //也就是从字符串的右侧开始查找特定字符首次出现的位置,并返回从字符串中的这个位置起,一直到字符串结束的所有字符
cout<<label<<endl; /* /cam16499_url2_copy.sdp */
int split=label.find('_');
if (split>0)
{
ID=label.substr(0,split); //返回一个从指定位置开始的指定长度的字符串
}
cout<<ID<<endl; /* /cam16499 */
camID=ID.substr(4,(strlen(ID.c_str())-4));
cout<<camID<<endl; /* 16499 */
char out_im[100];
sprintf(out_im,"%s%s","/home/cstor/Image/",camID.c_str());
cout<<out_im<<endl;
mkdir(out_im,0777);
char outna[100];
sprintf(outna,"%s%c%s",out_im,'/',label1);
cout<<outna<<endl;
mkdir(outna,0777);
}