Is there any crossplatform C\C++ lib for files searching? (on hard drive) What I need is simple - be able to find all images on users computer in all folders and subfolders with sise >= 200kb.
How to do such thing? Can any one help me? Please.
Is there any crossplatform C\C++ lib for files searching? (on hard drive) What I need is simple - be able to find all images on users computer in all folders and subfolders with sise >= 200kb.
How to do such thing? Can any one help me? Please.
Boost.Filesystem
is a great library. Here is a code I wrote while ago, you can change the search criteria easily once you know the library(you can query the size and the extension):
#include <iostream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
void find_file(const path& root, const string& file_name, vector<path>& found_files)
{
directory_iterator current_file(root), end_file;
bool found_file_in_dir = false;
for( ; current_file != end_file; ++current_file)
{
if( is_directory(current_file->status()) )
find_file(*current_file, file_name, found_files);
if( !found_file_in_dir && current_file->leaf() == file_name )
{
// Now we have found a file with the specified name,
// which means that there are no more files with the same
// name in the __same__ directory. What we have to do next,
// is to look for sub directories only, without checking other files.
found_files.push_back(*current_file);
found_file_in_dir = true;
}
}
}
int main()
{
string file_name;
string root_path;
vector<path> found_files;
std::cout << root_path;
cout << "Please enter the name of the file to be found(with extension): ";
cin >> file_name;
cout << "Please enter the starting path of the search: ";
cin >> root_path;
cout << endl;
find_file(root_path, file_name, found_files);
for( std::size_t i = 0; i < found_files.size(); ++i)
cout << found_files[i] << endl;
}
ACE has a lot of cross-platform wrappers. In your particular case see ACE_Dirent or ACE_OS::scandir / ACE_OS::opendir / ACE_OS::readdir and friend functions. ACE is very powerful abstraction layer between operating systems. If you need such things then this is the way to go.