网站地图    收藏   

主页 > 系统 > linux系统 >

linux之根据时间段查询目录底下文件名 - Linux操作

来源:自学PHP网    时间:2015-04-14 11:51 作者: 阅读:

[导读] [cpp] view plaincopyprint?文件名如下:[cpp] view plaincopyprint?1970_01_01_00_05_07_picture_000000231.jpg1970_01_01_00_05_08_picture_000000232.jpg1970_01_01_00_05_10_picture_000000233.jpg1970_......

[cpp] view plaincopyprint?
文件名如下: 
[cpp] view plaincopyprint?
1970_01_01_00_05_07_picture_000000231.jpg 
1970_01_01_00_05_08_picture_000000232.jpg 
1970_01_01_00_05_10_picture_000000233.jpg 
1970_01_01_00_05_11_picture_000000234.jpg 
1970_01_01_00_05_12_picture_000000235.jpg 
1970_01_01_00_05_13_picture_000000236.jpg 
1970_01_01_00_05_14_picture_000000237.jpg 
1970_01_01_00_05_15_picture_000000238.jpg 
1970_01_01_00_05_16_picture_000000239.jpg 
1970_01_01_00_05_18_picture_000000240.jpg 
1970_01_01_00_05_19_picture_000000241.jpg 
1970_01_01_00_05_20_picture_000000242.jpg 
1970_01_01_00_05_21_picture_000000243.jpg 
1970_01_01_00_05_22_picture_000000244.jpg 
1970_01_01_00_05_23_picture_000000245.jpg 
1970_01_01_00_05_25_picture_000000246.jpg 
1970_01_01_00_05_26_picture_000000247.jpg 
1970_01_01_00_05_27_picture_000000248.jpg 
1970_01_01_00_05_28_picture_000000249.jpg 
[cpp] view plaincopyprint?
  
[cpp] view plaincopyprint?
#include <QtCore/QCoreApplication> 
#include <sys/types.h> 
#include <dirent.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <vector> 
#include <iostream> 
#include <string> 
using namespace std; 
 
int main(int argc, char *argv[]) 

    QCoreApplication a(argc, argv); 
 
  
    string str2= "1970_01_01_00_45_01"; 
    string str1 = "1970_01_01_00_44_00"; 
     
    DIR*   dp; 
    struct   dirent*   dirp; 
 
    if((dp   =   opendir("/mnt/picture"))   ==   NULL   ) 
    { 
        printf( "Can   not   open\n\n "); 
 
    } 
    vector<string> vecPicname; 
    bool flag1=false,flag2=false; 
    while((dirp   =   readdir(dp))   !=   NULL   ) 
    { 
        if(dirp->d_name[0] =='.' ) 
        { 
            continue; 
        } 
 
        printf( "%s\n ",dirp-> d_name); 
        string strTemp = dirp-> d_name; 
        strTemp = strTemp.substr(0,19); 
 
        if(strTemp.compare(str1)>=0 &&strTemp.compare(str2)<=0) 
        { 
            cout<<"wyz---------"<<strTemp<<endl; 
 
            vecPicname.push_back(dirp-> d_name); 
        } 
 
 
 
        if(strTemp.compare(str1) ==0) 
        { 
            flag1=true; 
        } 
        if(strTemp.compare(str2) ==0) 
        { 
            flag2=true; 
        } 
 
        if(flag1==true && flag2==true) 
        { 
            break; 
        } 
 
    } 
 
 
    for(unsigned int i=0; i<vecPicname.size(); i++) 
    { 
        cout<<"wyz------"<<vecPicname[i]<<endl; 
    } 
 
    closedir(dp); 
    return a.exec(); 

结果查询到在某时间段自己想要的文件名 ,及图片

摘自 Ivan@_linux专栏

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论