Example #1
0
    inline
    void remove_all(const boost::filesystem::path& path)
    {
      if (__is_directory(path)) {
	std::vector<boost::filesystem::path> paths;
	
#if BOOST_FILESYSTEM_VERSION == 2
	DIR* dirp = (path.empty() ? ::opendir(".") : ::opendir(path.directory_string().c_str()));
#else
	DIR* dirp = (path.empty() ? ::opendir(".") : ::opendir(path.string().c_str()));
#endif
	if (dirp) {
	  struct dirent* dp;
	  do {
	    errno = 0;
	    if ((dp = readdir(dirp)) != 0) {
	      const std::string path_leaf(dp->d_name);
	      if (path_leaf != "." && path_leaf != "..")
		paths.push_back(path / path_leaf);
	    }
	  } while (dp);
	  ::closedir(dirp);
	}
	std::for_each(paths.begin(), paths.end(), utils::filesystem::remove_all);
      }

#if BOOST_FILESYSTEM_VERSION == 2
      if (__exists(path))
	::remove(path.file_string().c_str());
#else
      if (__exists(path))
	::remove(path.string().c_str());
#endif
      errno = 0;
    }
Example #2
0
void display( const bfs::path & p)
{
	long int fc=0,dc=0,ec=0,oc=0;

if( bfs::is_directory(p))
{

	cout<<"In Directory:"<< p.directory_string()<<"\n\n";

	bfs::directory_iterator i(p), e;
	

	for(i;i!=e;++i)
	{
		if(bfs::is_directory( i->status()))
		{
			dc++;
			display(*i);
			//cout<< i->path().filename()<<"[directory]\n";
		}
		else if(bfs::is_regular_file(i->status()))
		{
			fc++;
			cout<<i->path().filename()<<"[file]\n";
		}
		else
		{
			oc++;
			cout<<i->path().filename()<<"[others]\n";
		}


	}
	cout<<"File Count:"<<fc<<"\n";
	cout<<"Directory COunt"<<dc<<"\n";
	cout<<"Others Count"<<oc<<"\n";

}
else
{
	cout<<"File Found"<<p.file_string()<<"\n\n";
}


}