|
发表于 2008-9-26 23:36:27
|
显示全部楼层
换个更简单的c++解决方案,用boost::filesystem
#pragma once
#include <boost/filesystem/operations.hpp>
#include <deque>
#include <vector>
#include <algorithm>
using namespace std;
using namespace boost;
class FileHelper
{
public:
static bool findFile(filesystem::path const& dirPath,std::string const& fileName,filesystem::path & pathFound )
{
if ( !exists( dirPath ) )
return false;
filesystem::directory_iterator end_itr; // default construction yields past-the-end
for (filesystem::directory_iterator itr( dirPath );itr != end_itr;++itr )
{
if (filesystem::is_directory(itr->status()) )
{
if (findFile( itr->path(), fileName, pathFound ) )
return true;
}
else if ( itr->path().leaf() == fileName ) // see below
{
pathFound = itr->path();
return true;
}
}
return false;
} |
|