Linux之根據時間段查詢目錄底下文件名
文件名如下:
- 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
- #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();
- }
結果查詢到在某時間段自己想要的文件名 ,及圖片
for(int i=0; i<100; i++) //刪除最早的抓拍圖片100張
{
system("rm -f /sddisk/picture/$(ls /sddisk/picture -rt | sed -n '1p')");
}