Linux下制定路径下 c创建文件夹 名字用时间来命名

10 篇文章 0 订阅

在给定的路径下建立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);

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值