C++:boost文件系统返回超过特定时间的文件列表

oli*_*dev 9 c++ boost-filesystem

我正在使用Boost::FileSystem在Linux平台下运行的C++库,我有一个问题如下:

我想要一个比给定日期时间更早修改的文件列表.我不知道是否boost::FileSystem提供这样的方法:

vector<string> listFiles = boost::FileSystem::getFiles("\directory", "01/01/2010 12:00:00");
Run Code Online (Sandbox Code Playgroud)

如果是,请提供示例代码?

nab*_*lke 14

Boost :: filesystem不提供完全相同的功能.但你可以用这个:

http://www.boost.org/doc/libs/1_45_0/libs/filesystem/v3/doc/reference.html#last_write_time

作为编写自己的基础.以下是使用last_write_time的一些示例代码:

#include <boost/filesystem/operations.hpp>
#include <ctime>
#include <iostream>

int main( int argc , char *argv[ ] ) {
   if ( argc != 2 ) {
      std::cerr << "Error! Syntax: moditime <filename>!\n" ;
      return 1 ;
   }
   boost::filesystem::path p( argv[ 1 ] ) ;
   if ( boost::filesystem::exists( p ) ) {
      std::time_t t = boost::filesystem::last_write_time( p ) ;
      std::cout << "On " << std::ctime( &t ) << " the file " << argv[ 1 ] 
     << " was modified the last time!\n" ;
      std::cout << "Setting the modification time to now:\n" ;
      std::time_t n = std::time( 0 ) ;
      boost::filesystem::last_write_time( p , n ) ; 
      t = boost::filesystem::last_write_time( p ) ;
      std::cout << "Now the modification time is " << std::ctime( &t ) << std::endl ;
      return 0 ;
   } else {
      std::cout << "Could not find file " << argv[ 1 ] << '\n' ;
      return 2 ;
   }
}
Run Code Online (Sandbox Code Playgroud)