Ejemplo n.º 1
0
void list_files( const fs::path& p, std::vector<std::string>& v)
{
   if ( fs::exists(p) && fs::is_directory( p ) ) {
      fs::directory_iterator end_iter;
      for ( fs::directory_iterator dir_itr( p );
            dir_itr != end_iter;
            ++dir_itr ) {
         try {
            if ( !fs::is_directory( *dir_itr ) ) {
#if BOOST_VERSION >= 103400
               v.push_back(dir_itr->path().file_string());
#else
               v.push_back(dir_itr->native_file_string());
#endif
            }
         } catch ( const std::exception& ex ) {
#if BOOST_VERSION >= 103400
            edglog(warning) << dir_itr->path().file_string() << ' ' << ex.what() << std::endl;
#else
            edglog(warning) << dir_itr->native_file_string() << ' ' << ex.what() << std::endl;
#endif
         }
      }
   }
}
Ejemplo n.º 2
0
void ImagesManager::loadImagesFromFolder(Images image, std::string path) {
    std::vector<std::string> *vectorImages = new std::vector<std::string>();

    if (!boost::filesystem::exists(path)) {
        return;
    }

    boost::filesystem::directory_iterator end_iter;
    if (boost::filesystem::is_directory(path)) {
        for (boost::filesystem::directory_iterator dir_itr(path); dir_itr != end_iter; ++dir_itr) {
            try {
                boost::filesystem::file_status status = dir_itr->status();
                if (fs::is_directory(status)) {
                    continue;

                } else if (fs::is_regular_file(status)) {
                    std::string pathFilename = dir_itr->path().string();
                    images[pathFilename] = *new sf::Texture;
                    images[pathFilename].loadFromFile(pathFilename);
                    vectorImages->push_back(pathFilename);

                }
            } catch (const std::exception &ex) {
                std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
            }
        }
    }

    groupImages[image] = vectorImages;

}
Ejemplo n.º 3
0
		void
		MapBackgroundManager::Initialize (const boost::filesystem::path& backgroundsDir)
		{
			for (std::map<std::string, MapBackgroundManager*>::const_iterator iter = _managers.begin ();
				 iter != _managers.end ();
				 ++iter)
			{
				delete iter->second;
			}
			_managers.clear ();

			if (fs::exists (backgroundsDir) == false)
			{
			Log::GetInstance ().warn ("Map backgrounds dir does not exist : " + backgroundsDir.string ());
			return;
			}

			// Create all managers
			fs::directory_iterator end_iter;
			for ( fs::directory_iterator dir_itr( backgroundsDir );
			  dir_itr != end_iter;
			  ++dir_itr )
			{
			std::string dirpath = dir_itr->leaf();

			MapBackgroundManager* manager = new MapBackgroundManager (backgroundsDir / dirpath);
			_managers.insert (std::make_pair (dirpath, manager));
			}

		}
Ejemplo n.º 4
0
void players_db::read(std::vector<player>& players) const throw(players_db_exception)
{
  fs::path full_path = fs::system_complete( path );
  
  if (!fs::is_directory(full_path)) {
    throw players_db_exception("database does not exist");
  }
  
  fs::directory_iterator end_iter;
  
  for ( fs::directory_iterator dir_itr( full_path );
        dir_itr != end_iter;
        ++dir_itr )
  {
    player p(dir_itr->path());
    
    if (p.grammar_error) {
      // silently ignore bad player files
      continue;
    }
    
    if (filter_set.size() > 0) {
      if (filter_set.find(p.name) == filter_set.end()) {
        continue;
      }
    }
    
    players.push_back(p);
  }
}
Ejemplo n.º 5
0
bool Utility_Functions::remove_files_with_extension_from_dir(bfs::path &dir,const std::string &extension)
{
    //  Cria um iterator para indicar fim do diretorio
    bfs::directory_iterator end_itr;

    //  Cria um iterator para percorrer o diretorio
    bfs::directory_iterator dir_itr(dir);

    boost::system::error_code ec;

    //  Le os nomes dos "fpack" primeiros arquivos
    for( ; dir_itr != end_itr; ++dir_itr)
    {
        if(bfs::is_regular_file(dir_itr->status()) )
        {
            if( !extension.compare(dir_itr->path().extension().string()) )
            {
                //std::cout << "\nRemoving file: " << dir_itr->path().string();
                bfs::remove(dir_itr->path(),ec);

                if(ec)
                {
                    return false;
                }
            }
        }
    }

    return true;
}
Ejemplo n.º 6
0
void PeopleFlowStreamInput::initial() 
{
	//get one people flow folder path from the configure file

	for(int i = 0; i<dataFolderVector.size(); i++)
	{
		std::string peopleFlowFolder = dataFolderVector[i];
		boost::filesystem::path peopleFlowFolderFullPath( boost::filesystem::initial_path() );
		peopleFlowFolderFullPath = boost::filesystem::system_complete( boost::filesystem::path( peopleFlowFolder) );
		//peopleFlowFolderFullPath = boost::filesystem::system_complete( boost::filesystem::path( peopleFlowFolder, boost::filesystem::native ) );
		assert ( boost::filesystem::exists( peopleFlowFolderFullPath ) );
		assert ( boost::filesystem::is_directory( peopleFlowFolderFullPath ) );
		boost::filesystem::directory_iterator end_iter;
		//scan the folder and get each wrapper file
		for (  boost::filesystem::directory_iterator dir_itr( peopleFlowFolderFullPath );dir_itr != end_iter;	++dir_itr )
		{

			assert ( boost::filesystem::is_regular_file( *dir_itr ) );

			boost::filesystem::path peopleFlowFilePath= dir_itr->path();
			//wrapper file path
			std::string peopleFlowFileFullPath = peopleFlowFilePath.string();
			std::string extensionFilename = peopleFlowFileFullPath.substr(peopleFlowFileFullPath.find_last_of(".")+1);

			if(extensionFilename != "csv")
			{
				continue;
			}
			//add the file to the global list
			this->peopleFlowFileList.push_back(peopleFlowFileFullPath);
		}
	}
	this->currentPeopleFlowFileListIterator = this->peopleFlowFileList.begin();
	this->currentFileStream.open((*peopleFlowFileList.begin()).c_str());
}
Ejemplo n.º 7
0
static bool getLastStore( std::string p, NodeAttr *attr )
{
   std::string path;

   auto dir = path_get( PathType::BAK, boost::filesystem::path(p).filename().c_str() );

   boost::system::error_code ec;

   bool succ = false;

   boost::filesystem::directory_iterator dir_itr( dir, ec );
   if ( ec == 0 )
   {
      boost::filesystem::directory_iterator dir_end;

      for ( ; dir_itr != dir_end; ++dir_itr )
      {
         auto &filepath = *dir_itr;
         if ( filepath.path( ).string( ) > path )
            path = filepath.path( ).string( );
      }

      attr->clear( );
      if ( !path.empty( ) )
      {
         boost::spirit::classic::file_iterator<char> fi( path );
         if ( fi )
            succ = attr->parse( &*fi );
      }
   }

   return succ;
}
Ejemplo n.º 8
0
boost::any LuaGraphTreeModel::getChild(const boost::any& parent, const UInt32& index) const
{
    try
    {
        BoostPath ThePath = boost::any_cast<BoostPath>(parent);

        if(!ThePath.empty() &&
           boost::filesystem::exists(ThePath))
        {
            boost::filesystem::directory_iterator end_iter;
            UInt32 Count(0);
            for ( boost::filesystem::directory_iterator dir_itr(ThePath); dir_itr != end_iter; ++dir_itr )
            {
                if( isValidFile(dir_itr->path()) )
                {
                    if(Count == index)
                    {
                        return boost::any(dir_itr->path());
                    }
                    ++Count;
                }
            }
        }
        return boost::any();
    }
    catch(boost::bad_any_cast &)
    {
        return boost::any();
    }
}
Ejemplo n.º 9
0
/*!
 * Load all modules in a given path.
 * This will recurse into sub-directories.
 * Does not throw, prints to std error.
 * \param path the filesystem path
 */
static void load_module_path(const fs::path &path){
    if (not fs::exists(path)){
        //std::cerr << boost::format("Module path \"%s\" not found.") % path.file_string() << std::endl;
        return;
    }

    //try to load the files in this path
    if (fs::is_directory(path)){
        for(
            fs::directory_iterator dir_itr(path);
            dir_itr != fs::directory_iterator();
            ++dir_itr
        ){
            load_module_path(dir_itr->path());
        }
        return;
    }

    //its not a directory, try to load it
    try{
        load_module(path.file_string());
    }
    catch(const std::exception &err){
        std::cerr << boost::format("Error: %s") % err.what() << std::endl;
    }
}
Ejemplo n.º 10
0
std::vector<std::string> listFiles(const std::string& directory_path, const std::string& regex_str)
{
  namespace fs = boost::filesystem;

  std::vector<std::string> results;

  // Check given path
  if( !fs::exists( directory_path ) ||
      !fs::is_directory( directory_path ) )
    return results;

  // Create regex
  const boost::regex regex {regex_str};

  // List files
  fs::directory_iterator end_iter;
  for( fs::directory_iterator dir_itr( directory_path ); dir_itr != end_iter; ++dir_itr )
  {
    if( fs::is_regular_file( dir_itr->status() ) &&
        boost::regex_match( dir_itr->path().filename().string(), regex ))
      results.emplace_back( dir_itr->path().filename().string() );
  }

  // Alphabetically sort
  std::sort( results.begin(), results.end() );

  return results;
}
Ejemplo n.º 11
0
int main() {
    fs::directory_iterator end_iter;
    for (fs::directory_iterator dir_itr("tests/cases"); dir_itr != end_iter;
         ++dir_itr) {
        std::string path = dir_itr->path().string();
        std::cout << "Case: " << path << std::endl;
        test_case(path);
    }
}
Ejemplo n.º 12
0
void MainWindow::import_data2db()
{
	int bRes;
	QString path_name = QFileDialog::getExistingDirectory(this);

	if (path_name.isNull())
		return;

	QDirIterator dir_itr(path_name, QDir::Files, QDirIterator::Subdirectories);
	bdbXMLInterface db_interface;
	while (dir_itr.hasNext())
	{
		QString cur_pathname = dir_itr.next();

		QFileInfo cur_file(cur_pathname);
		if (!cur_file.isFile())
			continue;

		QString cur_filename = cur_file.fileName();

		//file name is ended with .xml?
		QString xml_ext(".xml");
		if (!cur_filename.endsWith(xml_ext, Qt::CaseInsensitive))
		{
			continue;
		}
		else 
		{
			int str_len = cur_filename.size();
			cur_filename.remove(str_len - 4, 4);
		}

		BdRetVal bsucc = db_interface.add_files(cur_pathname.toStdString(), cur_filename.toStdString());
		//add to directory
	}

	Driver driver;
	try
	{
		bool errno = driver.beginSimulation ();

		if (errno == 0)
		{
			QStringList par_list;
			QString pro_name("../../../ExternalLib/linux/CopasiUI");
			QString par_1("-i");
			QString par_2("network.xml");
			par_list << par_1 << par_2;
			QProcess::execute(pro_name, par_list);
		}
	}
	catch (CoreException &se)
	{
		cout << "exceptions" << endl;
	}
}
Ejemplo n.º 13
0
vector<string> Unix_Utility::read_dir(string path)
{
   vector<string> result;
   fs::directory_iterator end_itr;
   for ( fs::directory_iterator dir_itr( path ) ; dir_itr != end_itr; ++dir_itr )
   {
      result.push_back( dir_itr->path().file_string() );
   }
   return result;
}
Ejemplo n.º 14
0
/*
 Returns json struct of filenames in job files folder.
*/
onion_connection_status OnionServer::getJobFolder(
		Onion::Request &req, Onion::Response &res ){

	std::string &folder = m_b9CreatorSettings.m_b9jDir;
	std::ostringstream json_reply;

	fs::path full_path = fs::system_complete( fs::path( folder ) );

	unsigned long file_count = 0;

	json_reply << "{ \"name\" : \"" << folder << "\", \"content\" : [" ;

	if( !fs::exists( full_path ) ){
		std::cout << "Not found: " << full_path.filename() << std::endl;
		json_reply << "\"none\"";
	}else if ( !fs::is_directory( full_path ) ){
		std::cout << "Path is no directory: " << full_path.filename() << std::endl;
		json_reply << "\"none\"";
	}else{
		fs::directory_iterator end_iter;
		for ( fs::directory_iterator dir_itr( full_path );
				dir_itr != end_iter;
				++dir_itr )
		{
			try
			{
				if (! fs::is_directory( dir_itr->status() ) )
				{ //regluar file or symbolic link
					if( file_count ) json_reply << ", " << std::endl;
					json_reply << "{ \"" << file_count << "\":	" \
						<< dir_itr->path().filename() << " }";
					++file_count;
				}
				/*Remark: The index numbers are sourounded by "'s
				 * to avoid problems on the javascript side.
				 * I.E. {"0" : "filename" }.
				 * */

			}
			catch ( const std::exception & ex )
			{
				std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
			}
		}
	}

	json_reply << "] }" ;

	std::string json_replyStr = json_reply.str();
	size_t len = json_replyStr.size();
	res.write(json_replyStr.c_str(), (int) len );
	return OCS_PROCESSED;
}
Ejemplo n.º 15
0
void reset() {
	if (!boost::filesystem::is_directory(TEST_PATH)) {
		return;
	}
	boost::filesystem::directory_iterator end_iter;
	for (boost::filesystem::directory_iterator dir_itr(TEST_PATH); dir_itr != end_iter; ++dir_itr) {
		if (boost::filesystem::is_regular_file(dir_itr->status())) {
			std::string fileName = dir_itr->path().filename();
			if (fileName.find("failover") == 0) {
				boost::filesystem::remove(dir_itr->path().filename());
			}
		}
	}
}
Ejemplo n.º 16
0
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) 
{
	// set world directory
// fixme : boost should use a codecvt_facet but for now we convert to UCS-2
#ifdef _WIN32
	fs::path full_path( utf8_to_ucs2( dir ) );
#else
	fs::path full_path( dir );
#endif
	fs::directory_iterator end_iter;

	for( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
	{
		try
		{
			std::string current_dir = dir_itr->path().filename().string();

			// only directories with an existing description
			if( fs::is_directory( *dir_itr ) && File_Exists( dir + "/" + current_dir + "/description.xml" ) )
			{
				cOverworld *overworld = Get_from_Path( current_dir );

				// already available
				if( overworld )
				{
					overworld->m_description->m_user = 2;
					continue;
				}

				overworld = new cOverworld();

				// set path
				overworld->m_description->m_path = current_dir;
				// default name is the path
				overworld->m_description->m_name = current_dir;
				// set user
				overworld->m_description->m_user = user_dir;

				objects.push_back( overworld );

				overworld->Load();
			}
		}
		catch( const std::exception &ex )
		{
			printf( "%s %s\n", dir_itr->path().filename().string().c_str(), ex.what() );
		}
	}
}
Ejemplo n.º 17
0
		MapBackgroundManager::MapBackgroundManager(const boost::filesystem::path& backgroundDir)
		{
			Log::GetInstance ().debug ("Initializing backgrounds in " + backgroundDir.string ());

			// Go through each scale directory
			fs::directory_iterator end_iter;
		   for ( fs::directory_iterator dir_itr( backgroundDir );
				  dir_itr != end_iter;
				  ++dir_itr )
			{
				std::string dirpath = dir_itr->string();

				const MapBackground* background = new MapBackground (dirpath);
				_backgrounds.push_back (background);
			}
		}
Ejemplo n.º 18
0
void
FileSystemMap::BuildMap(
		fs::path const& FullPathName)
{
	fs::directory_iterator end_iter;
	for (fs::directory_iterator dir_itr(FullPathName); dir_itr != end_iter;
			++dir_itr) {
		try {
			if (fs::is_directory(dir_itr->status())) {
				++DirCount;
#ifdef __DEBUG__FSM
				std::cout << "entering directory: "
						<< dir_itr->path().filename() << endl;
#endif
				BuildMap(dir_itr->path());
			} else if (fs::is_regular_file(dir_itr->status())) {
				++FileCount;
				string s(dir_itr->path().c_str());
#ifdef __DEBUG__FSM
				std::cout << "\tchunking file #" << FileCount << " " << s
						<< endl;
#endif

				//FileDescType fd(s);
				auto ap = FileMap.insert(make_pair(s, FileDescType(s)));
				if (ap.second)	//new item was inserted
				{
					auto vd = mCntGraph.AddVertex(&ap.first->second);	//add the new file to the boost graph as a vertex
					ap.first->second.VertexDesc((void*)vd);				//add shortcut pointer to the vertex descriptor to Fileobj
				}
				ChunkFile((*ap.first).second);

			} else {
				++OtherCount;
#ifdef __DEBUG__FSM
				std::cout << "Other found :" << dir_itr->path().filename()
						<< endl;
#endif
			}

		} catch (const std::exception & ex) {
			++ErrCount;
			std::cout << ex.what() << std::endl;
		}
	}
	return;
}
Ejemplo n.º 19
0
std::vector<AString> list_dir(AString dir) {
    std::vector<AString> result;
    if (!fs::exists(dir)) {
        return result;
    }
    else if (!fs::is_directory(dir)) {
        return result;
    }
    else {
        fs::directory_iterator end_iter;
        for ( fs::directory_iterator dir_itr( dir ); dir_itr != end_iter; ++dir_itr ) {
            AString filename = dir_itr->path().filename().string();
            result.push_back(filename);
        }
    }
    return result;
}
static void load_all_modules_in_path(const fs::path &path)
{
    if (not fs::exists(path)) return;
    if (fs::is_regular_file(path))
    {
        const std::string mod_path = path.string();
        if (not load_module_in_path(mod_path.c_str()))
        {
            std::cerr << "GRAS Module loader fail: " << mod_path << std::endl;
        }
        return;
    }
    if (fs::is_directory(path)) for(
        fs::directory_iterator dir_itr(path);
        dir_itr != fs::directory_iterator();
        ++dir_itr
    ) load_all_modules_in_path(dir_itr->path());
}
Ejemplo n.º 21
0
void plugin_manager_t::load_plugins_in_directory( const boost::filesystem::path& p)
{
    // TODO: error handling, recurse

    if( !boost::filesystem::exists( p))
        return;

    boost::filesystem::directory_iterator end_iter;
    for( boost::filesystem::directory_iterator dir_itr( p); dir_itr != end_iter; ++dir_itr)
    {
        if( boost::filesystem::is_regular_file( dir_itr->status()))
            load_plugin( *dir_itr);
        else
        {
            if( boost::filesystem::is_directory( dir_itr->status()))
				load_plugins_in_directory( *dir_itr);
        }
    }
}
Ejemplo n.º 22
0
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) 
{
	// set world directory
	fs::path full_path( dir, fs::native );
	fs::directory_iterator end_iter;

	for( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
	{
		try
		{
			std::string current_dir = dir_itr->path().leaf();

			// only directories with an existing description
			if( fs::is_directory( *dir_itr ) && File_Exists( dir + "/" + current_dir + "/description.xml" ) )
			{
				// already available
				if( Get_from_Path( current_dir ) )
				{
					continue;
				}

				cOverworld *overworld = new cOverworld();

				// set path
				overworld->m_description->m_path = current_dir;
				// default name is the path
				overworld->m_description->m_name = current_dir;
				// set user
				overworld->m_description->m_user = user_dir;

				objects.push_back( overworld );

				overworld->Load();
			}
		}
		catch( const std::exception &ex )
		{
			printf( "%s %s\n", dir_itr->path().leaf().c_str(), ex.what() );
		}
	}
}
Ejemplo n.º 23
0
	void listFiles(std::string dirname, std::vector<std::string> &filenames) {
		fs::path full_path(fs::initial_path<fs::path>());
		full_path = fs::system_complete(fs::path(dirname));

		if (!fs::exists(full_path)) {
			std::cout << "\nNot found: " << dirname << std::endl;
			return;
		}

		unsigned long file_count = 0;
		unsigned long dir_count = 0;
		unsigned long other_count = 0;
		unsigned long err_count = 0;

		if (fs::is_directory(full_path)) {
			std::cout << "\nIn directory: " << dirname << "\n\n";
			fs::directory_iterator end_itr;
			for (fs::directory_iterator dir_itr(full_path); dir_itr != end_itr; ++dir_itr) {
				try {
					if (fs::is_directory(dir_itr->status())) {
						++dir_count;
						std::cout << dir_itr->path().filename() << " [directory]\n";
					} else if (fs::is_regular_file(dir_itr->status())) {
						++file_count;
						filenames.push_back(dirname + "/" + dir_itr->path().filename().string());
						std::cout << dir_itr->path().filename() << "\n";
					} else {
						++other_count;
						std::cout << dir_itr->path().filename() << " [other]\n";
					}
				} catch (const std::exception &ex) {
					++err_count;
					std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
				}
			}
			std::cout << "\n" << file_count << " files\n"
			          << dir_count << " directories\n"
					  << other_count << " others\n"
					  << err_count << " erros\n";
		}
	}
Ejemplo n.º 24
0
string_vec System::get_files(string this_path)
{
	string_vec vs;
	fs::directory_iterator end_itr;

	if (fs::exists(this_path))
	{
		fs::directory_iterator end_itr;
		for ( fs::directory_iterator dir_itr(this_path);
				dir_itr != end_itr;
				dir_itr++)
		{
			if ( fs::is_regular_file( dir_itr->status() ) )
			{
				vs.push_back( dir_itr->path().filename() );
			}
		}
	}

	return vs;
}
Ejemplo n.º 25
0
UInt32 LuaGraphTreeModel::getIndexOfChild(const boost::any& parent, const boost::any& child) const
{
    try
    {
        BoostPath ParentPath = boost::any_cast<BoostPath>(parent);
        BoostPath ChildPath = boost::any_cast<BoostPath>(child);

        if(!ParentPath.empty() &&
           boost::filesystem::exists(ParentPath))
        {
            boost::filesystem::directory_iterator end_iter;
            UInt32 Count(0);
            for ( boost::filesystem::directory_iterator dir_itr( ParentPath ); dir_itr != end_iter; ++dir_itr )
            {
                try
                {
                    if(ChildPath == dir_itr->path() || boost::filesystem::equivalent(dir_itr->path(), ChildPath))
                    {
                        return Count;
                    }
                }
                catch(boost::filesystem::filesystem_error &)
                {
                    return Count;
                }
                if(isValidFile(dir_itr->path()))
                {
                    ++Count;
                }
            }
        }
        return 0;
    }
    catch(boost::bad_any_cast &)
    {
        return 0;
    }
}
Ejemplo n.º 26
0
void LetterClassifier::GetTrainingImagesFilename(const std::string input_dir, std::vector< std::vector< std::string > > &file_names, std::vector< std::string > &classes)
{
	namespace fs = boost::filesystem;
	std::vector< std::string > ImageFileTypes {".jpg", ".png", ".pgm", ".JPG"};
	fs::path full_path( fs::initial_path<fs::path>() );
	full_path = fs::system_complete( fs::path( input_dir ) );

	if ( !fs::exists( full_path ) )
	{
		std::cout << "\nNot found: " << full_path.native() << std::endl;
		return;
	}

	if ( fs::is_directory( full_path ) )
	{
		std::cout << "\nIn directory: " << full_path.native() << "\n\n";
		fs::directory_iterator end_iter;
		for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
		{
			try
			{
				if ( fs::is_directory( dir_itr->status() ) )
				{
					std::string dir_name = dir_itr->path().filename().native();
					if (!dir_name.empty())
					{
						const char *cstr = dir_name.c_str();
						if (cstr[0] != '.')
						{
							classes.push_back(dir_name);
							std::vector< std::string > fileNames;
							fileNames.clear();
							for ( fs::directory_iterator file_itr( dir_itr->path() ); file_itr != end_iter; ++file_itr )
							{
								try {
									if (fs::is_regular_file(file_itr->status()))
									{
										std::string ext = file_itr->path().extension().native();
										bool exists = (std::find(ImageFileTypes.begin(), ImageFileTypes.end(), ext) != ImageFileTypes.end());
										if ( exists )
											fileNames.push_back(file_itr->path().native());
									}
								}
								catch ( const std::exception & ex )
								{
									std::cout << file_itr->path().filename() << " " << ex.what() << std::endl;
								}
							}
							std::sort(fileNames.begin(), fileNames.end());
							file_names.push_back(fileNames);
						}
					}
				}
			}
			catch ( const std::exception & ex )
			{
				std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
			}
		}
	}
	return;
}
Ejemplo n.º 27
0
void SaveISISNexus::selog() {
  // find log files with names <RawFilenameWithoutExt>_LogName.txt and save them
  // in potentialLogFiles
  std::vector<std::string> potentialLogFiles;
  Poco::File l_path(inputFilename);
  std::string l_filenamePart = Poco::Path(l_path.path()).getFileName();
  std::string::size_type i = l_filenamePart.find_last_of('.');
  if (i != std::string::npos) // remove the file extension
  {
    l_filenamePart.erase(i);
  }
  std::string base_name = l_filenamePart;
  boost::regex regex(l_filenamePart + "_.*\\.txt",
                     boost::regex_constants::icase);
  Poco::DirectoryIterator end_iter;
  for (Poco::DirectoryIterator dir_itr(Poco::Path(inputFilename).parent());
       dir_itr != end_iter; ++dir_itr) {
    if (!Poco::File(dir_itr->path()).isFile())
      continue;

    l_filenamePart = Poco::Path(dir_itr->path()).getFileName();

    if (boost::regex_match(l_filenamePart, regex)) {
      potentialLogFiles.push_back(dir_itr->path());
    }
  }

  Progress prog(this, 0.5, 1, potentialLogFiles.size());

  NXmakegroup(handle, "selog", "IXselog");
  NXopengroup(handle, "selog", "IXselog");

  // create a log for each of the found log files
  std::size_t nBase = base_name.size() + 1;
  for (auto &potentialLogFile : potentialLogFiles) {
    std::string logName = Poco::Path(potentialLogFile).getFileName();
    logName.erase(0, nBase);
    logName.erase(logName.size() - 4);
    if (logName.size() > 3) {
      std::string icp = logName.substr(0, 3);
      std::transform(icp.begin(), icp.end(), icp.begin(), toupper);
      if (icp == "ICP")
        continue;
    }

    std::ifstream fil(potentialLogFile.c_str());
    if (!fil) {
      g_log.warning("Cannot open log file " + potentialLogFile);
      continue;
    }

    start_time_str[10] =
        ' '; // make it compatible with boost::posix_time::ptime
    boost::posix_time::ptime start_time(
        boost::posix_time::time_from_string(start_time_str));
    start_time_str[10] = 'T'; // revert
    std::vector<float> time_vec;
    std::vector<std::string> str_vec;
    std::vector<float> flt_vec;
    std::string line;
    bool isNotNumeric = false;
    while (std::getline(fil, line)) {
      if (line.empty())
        continue;
      std::string date_time_str = line.substr(0, 19);
      date_time_str[10] = ' ';
      boost::posix_time::ptime time(
          boost::posix_time::time_from_string(date_time_str));
      boost::posix_time::time_duration dt = time - start_time;
      time_vec.push_back(float(dt.total_seconds()));
      std::istringstream istr(line.substr(20));
      // check if the data are numeric then save them in flt_vec
      if (!isNotNumeric) {
        float flt;
        istr >> flt;
        if (istr.bad() || istr.fail()) {
          isNotNumeric = true;
        } else {
          flt_vec.push_back(flt);
        }
      }
      str_vec.push_back(istr.str());
    }
    fil.close();
    NXmakegroup(handle, &logName[0], "IXseblock");
    NXopengroup(handle, &logName[0], "IXseblock");

    {
      saveString("vi_name", " ");
      saveString("set_control", " ");
      saveString("read_control", " ");
      float tmp = 0.0;
      saveFloatOpen("setpoint", &tmp, 1);
      putAttr("units", "mV");
      close();
    }

    NXmakegroup(handle, "value_log", "NXlog");
    NXopengroup(handle, "value_log", "NXlog");

    saveFloatOpen("time", &time_vec[0], static_cast<int>(time_vec.size()));
    putAttr("start", start_time_str);
    putAttr("units", "seconds");
    close();

    if (flt_vec.size() == str_vec.size()) {
      saveFloatOpen("value", &flt_vec[0], static_cast<int>(flt_vec.size()));
    } else {
      saveStringVectorOpen("value", str_vec);
    }
    putAttr("units", " ");
    close();

    saveString("name", " ");

    NXclosegroup(handle); // value_log

    NXclosegroup(handle); // logName

    prog.report();
  }
Ejemplo n.º 28
0
// ===== IMPLEMENTATIONS =======
std::map<std::string, scottgs::path_list_type> scottgs::getFiles(boost::filesystem::path dir)
{
	
	
	// This is a return object
	// REGULAR -> {file1r,file2r,...,fileNr}
	// DIRECTORY -> {file1d,file2d,...,fileNd}
	// ...
	std::map<std::string,path_list_type> directoryContents;
	
	// Change to the absolute system path, instead of relative
	//boost::filesystem::path dirPath(boost::filesystem::system_complete(dir));
	boost::filesystem::path dirPath(dir);
	
	// Verify existence and directory status
	if ( !boost::filesystem::exists( dirPath ) ) 
	{
		std::stringstream msg;
		msg << "Error: " << dirPath.string() << " does not exist " << std::endl;
		throw std::runtime_error(msg.str());
	}
	
	if ( !boost::filesystem::is_directory( dirPath ) ) 
	{
		std::stringstream msg;
		msg << "Error: " << dirPath.string() << " is not a directory " << std::endl;
		throw std::runtime_error(msg.str());
	}

	#if GJS_DEBUG_PRINT				
		std::cout << "Processing directory: " << dirPath.directory_string() << std::endl;
	#endif	

	// A director iterator... is just that, 
	// an iterator through a directory... crazy!
	boost::filesystem::directory_iterator end_iter;
	for ( boost::filesystem::directory_iterator dir_itr( dirPath );
		dir_itr != end_iter;
		++dir_itr )
	{
		// Attempt to test file type and push into correct list
		try
		{
			// if ( boost::filesystem::is_directory( dir_itr->status() ) )
			// {
			// 	// Note, for path the "/" operator is overloaded to append to the path
			// 	directoryContents[DIR_FILE].push_back(dir_itr->path());
			// #ifdef GJS_DEBUG_PRINT				
			// 				std::cout << dir_itr->path().filename() << " [directory]" << std::endl;
			// #endif
			// }
			if ( boost::filesystem::is_regular_file( dir_itr->status() ) )
			{
				directoryContents[REG_FILE].push_back(dir_itr->path());
			#ifdef GJS_DEBUG_PRINT				
							std::cout << "Found regular file: " << dir_itr->path().filename() << std::endl;
			#endif
			}
			// else
			// {
			// 	directoryContents[OTHER_FILE].push_back(dir_itr->path());
			// #ifdef GJS_DEBUG_PRINT				
			// 				std::cout << dir_itr->path().filename() << " [other]" << std::endl;
			// #endif
			// }

		}
		catch ( const std::exception & ex )
		{
			std::cerr << dir_itr->path().filename() << " " << ex.what() << std::endl;
		}
	}
	
	
	return directoryContents;
}
Ejemplo n.º 29
0
int _tmain(int argc, _TCHAR* argv[])
{
    try
	{
        po::options_description desc( "Options" );
        desc.add_options()
            ( "help,h", "Show detailed help." )
			( "options,p", "Show parameter information." )
			( "version,p", "Show version information." )
			( "input-file,i", po::value<std::vector<std::string>>(), "Define file(s) for the convertion input." )
			( "input-type,I", po::value<std::vector<std::string>>(), "Define file type(s) for automatic conversion of files in the working directory." )
			( "output-file,o", po::value<std::string>(), "Define file for the convertion output." )
			( "noheader,h", "Disable adding of header support defines." )
            ( "const,C", "Define array as const." )
			( "respectcase,r", "Disable converting file types into lower case." )
			( "wxnone,w", "Disable adding of wxWidgets support macro's." )
			( "wxheader,W", po::value<std::string>()->default_value( "wx/wx.h" ), "Select the header that includes wxWidgets (precompiled header?)." )
			( "appendtype,t", "Add the file type at the end of the identifier (myimage_png)." )
			( "text,T", "Disable binary output and use text output, converts feed codes to systems defaults." )
		;

        po::positional_options_description posdesc;
        posdesc.add( "input-file", -1 );

        po::variables_map opt;
        po::store( po::command_line_parser( argc, argv ).options( desc ).positional( posdesc ).run(), opt );
		po::store( po::parse_config_file( fs::ifstream( fs::path( "default.cfg" ) ), desc ), opt );
        po::notify( opt );

		std::cout << WXINCLUDE_INFO << std::endl;

		/* Show options when requested */
        if ( opt.count( "options" ) )
		{
			std::cout << desc << std::endl << std::endl;
            exit( 0 );
        }

		/* Show help when requested */
        if ( opt.count( "help" ) )
		{
			std::cout << WXINCLUDE_HELP;
			std::cout << std::endl << desc << std::endl << std::endl;
            exit( 0 );
        }

		/* Show version when requested */
        if ( opt.count( "version" ) )
		{
			std::cout << WXINCLUDE_VERSION << std::endl;
            exit( 0 );
        }

		/* Process */
        if ( opt.count( "input-file" ) || opt.count( "input-type" ) )
		{
			if ( opt.count( "output-file" ) )
			{	
				/* Create timer */
				boost::timer timer;

				/* Create output file */
				std::string headername( opt[ "output-file" ].as<std::string>() );

				fs::path outputpath( headername );
				fs::ofstream output( outputpath, std::ios::out | std::ios::trunc );

				/* Use buffer */
				char outbuffer[BUFFER_SIZE];
				output.rdbuf()->pubsetbuf( outbuffer, BUFFER_SIZE );

				if ( !opt.count( "text" ) )
					output.setf( std::ios::binary );

				if ( !output )
					throw std::runtime_error( "Failed to create output file!" );

				/* Show status */
				std::cout << "Build  : file '" << outputpath.leaf() << "'..." << std::endl;

				/* Get base name of file */
				headername = fs::basename( outputpath );

				/* Data string stream */
				std::ostringstream data;

				/* Write header start when wanted */
				if ( !opt.count( "noheader" ) )
					defineheader_start( data, headername, opt.count( "wxnone" ) ? false : true, opt.count( "const" ) ? true : false );

				/* Get defined or else default wx header */
				std::string includename( opt[ "wxheader" ].as<std::string>() );

				/* Write macros when wanted */
				if ( !opt.count( "wxnone" ) )
					definemacros( data, includename, opt[ "wxheader" ].defaulted() );

				/* Common input buffer */
				char inbuffer[BUFFER_SIZE];

				/* Process input files based on provided list */
				if ( opt.count( "input-file" ) )
				{
					std::vector<std::string> files( opt[ "input-file" ].as<std::vector<std::string>>() );

					BOOST_FOREACH( std::string& file, files )
					{
						fs::path inputpath( file );
						std::string fileext( fs::extension( inputpath ) );

						fs::ifstream input( inputpath, std::ios::in | std::ios::binary | std::ios::ate );
						input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); 

						if ( input.is_open() )
						{
							/* Show status */
							std::cout << "Process: file '" << file << "'..." << std::endl;

							/* Remove extension */
							boost::erase_last( file, fileext );

							if ( !opt.count( "respectcase" ) )
								boost::to_lower( fileext );

							/* Append type */
							if ( opt.count( "appendtype" ) )
							{
								boost::erase_first( fileext, "." );

								/* Static and NO copy constructor for speed */
								static boost::format fmt( "%1%_%2%" );
								file = boost::str( fmt % file % fileext );
							}

							/* Lower case names when wanted */
							if ( !opt.count( "respectcase" ) )
								boost::to_lower( file );

							/* Process file */
							definefile( data, input, file, opt.count( "const" ) ? true : false );
						}
						else
						{
							/* Only show warning, other files need to be processed */
							std::cout << "Warning: input file '" << file << "' failed to open." << std::endl;
						}
					}
				}

				/* Process input files based on provided type */
				if ( opt.count( "input-type" ) )
				{
					std::vector<std::string> types( opt[ "input-type" ].as<std::vector<std::string>>() );

					for ( fs::directory_iterator dir_itr( fs::initial_path() ); dir_itr != fs::directory_iterator(); ++dir_itr )
					{
						BOOST_FOREACH( std::string& type, types )
						{
							/* Normal file? */
							if ( fs::is_regular( dir_itr->status() ) )
							{
								/* Wanted type? */
								std::string fileext( fs::extension( dir_itr->path() ));

								bool equals = false;

								if ( opt.count( "respectcase" ) )
									equals = boost::equals( fileext, type );
								else
									equals = boost::iequals( fileext, type );

								if ( equals )
								{
									fs::ifstream input( dir_itr->path(), std::ios::in | std::ios::binary | std::ios::ate );
									input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); 

									std::string file( dir_itr->path().leaf() );

									if ( input.is_open() )
									{
										/* Show status */
										std::cout << "Process: file '" << file << "'..." << std::endl;

										/* Remove extension */
										boost::erase_last( file, fileext );

										/* Append type */
										if ( opt.count( "appendtype" ) )
										{
											boost::erase_first( fileext, "." );

											/* Static and NO copy constructor for speed */
											static boost::format fmt( "%1%_%2%" );
											file = boost::str( fmt % file % fileext );
										}

										/* Lower case names when wanted */
										if ( !opt.count( "respectcase" ) )
											boost::to_lower( file );

										/* Process file */
										definefile( data, input, file, opt.count( "const" ) ? true : false );
									}
									else
									{
										/* Only show warning, other files need to be processed */
										std::cout << "Warning: input file '" << file << "' failed to open." << std::endl;
									}
								}
							}
						}
					}
				}
Ejemplo n.º 30
0
int main( int argc, char* argv[] )
{
  pdalboost::progress_timer t( std::clog );

  fs::path full_path( fs::initial_path<fs::path>() );

  if ( argc > 1 )
    full_path = fs::system_complete( fs::path( argv[1] ) );
  else
    std::cout << "\nusage:   simple_ls [path]" << std::endl;

  unsigned long file_count = 0;
  unsigned long dir_count = 0;
  unsigned long other_count = 0;
  unsigned long err_count = 0;

  if ( !fs::exists( full_path ) )
  {
    std::cout << "\nNot found: " << full_path.file_string() << std::endl;
    return 1;
  }

  if ( fs::is_directory( full_path ) )
  {
    std::cout << "\nIn directory: "
              << full_path.directory_string() << "\n\n";
    fs::directory_iterator end_iter;
    for ( fs::directory_iterator dir_itr( full_path );
          dir_itr != end_iter;
          ++dir_itr )
    {
      try
      {
        if ( fs::is_directory( dir_itr->status() ) )
        {
          ++dir_count;
          std::cout << dir_itr->path().filename() << " [directory]\n";
        }
        else if ( fs::is_regular_file( dir_itr->status() ) )
        {
          ++file_count;
          std::cout << dir_itr->path().filename() << "\n";
        }
        else
        {
          ++other_count;
          std::cout << dir_itr->path().filename() << " [other]\n";
        }

      }
      catch ( const std::exception & ex )
      {
        ++err_count;
        std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
      }
    }
    std::cout << "\n" << file_count << " files\n"
              << dir_count << " directories\n"
              << other_count << " others\n"
              << err_count << " errors\n";
  }
  else // must be a file
  {
    std::cout << "\nFound: " << full_path.file_string() << "\n";    
  }
  return 0;
}