accessing folders and copying files .

So i have to write a program ...

Specification:
I have a folder names abc and inside that folder i have thousands of other folders
inside each of those folders there is a file with .bm extension.

I have to copy those .bmp file to a different directory and change the file names from 1..n . So basically all the .bmp file has to be in one directory.

I have some basic c++ knowledge , all i did was some college course work and i don't know where to start.
You don't have to write it entirely in C++. The heavy lifting can easily be taken care of by a Perl script as to moving and renaming of the files. The script can then be called by your C++ code. However, if the requirements are for it to be solely C++ you can try the following. In a simple case, you can scan through the directories and store the paths to those .bmps and then upon ending the search, call another routine to copy them over to the pre-specificied directory and delete the originals. There are so many better solutions(multithreaded) than this but start something and we will help you along the way.

The following link should get you started:

(Boost FileSystem ) http://www.boost.org/doc/libs/1_47_0/libs/filesystem/v3/doc/tutorial.html

Step 1 is to pick an API, Win32 makes this pretty easy but which libarary are you most comfortable with?
well , i went the boost way ,
It still has a lot of errors


#include <boost/filesystem.hpp>
#include <cstring>
using namespace boost::filesystem
int main()
{
bool recurse = true;
string pathDest = "C:\\Users\\admin\\Desktop\\asdfasdf";

// using namespace boost::filesystem;
recursive_directory_iterator it("C:\\Users\\admin\\Desktop\\test"), end;
for (; it != end; ++it)
{
int a = 0;
if (!recurse)
{
it.no_push(); // disable recurse
}
if (!is_regular_file(*it))
{
continue;
}
// make the validity check
auto filepath = it->path();

if(filepath.extension() == ".bmp")
{
// rename(const path& old_p, const path& new_p);
rename(filepath filepath.filename(), filepath a.tostring() );
copy_file(filepath, pathDest);
a++;

}


} // end for
}

Topic archived. No new replies allowed.