10

Boost::FileSystemLinux プラットフォームで実行されている C++ でライブラリを使用していますが、次の質問があります。

特定の日時よりも前に変更されたファイルのリストが必要です。boost::FileSystem次のような方法が提供されているかどうかはわかりません。

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

はいの場合、サンプルコードを提供していただけますか?

4

2 に答える 2

15

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 ;
   }
}
于 2010-11-25T16:47:14.197 に答える
1

std::map(last_write_time, fileName) を使用して、ファイルの最終変更時刻と絶対ファイル パスを保存し、順序通りに走査してデータを並べ替えることができます。

于 2013-11-10T18:00:17.413 に答える