I have an assignment where I need to go through all the files in a folder. For each file I need to know each unique file extension, how many files for each unique file extension, and the total size for each unique file extension. I have to be able to sort through this using either the file extension or the total size of the file extension. The first thing I thought of using was a map. This will keep track of each unique file extension and the amount of times that file extension was found. How do I now associate the total size of the file extension to my map? So for example I need the output to be something like this:
Using file extension for sort
.cpp : 1 : 3400
.exe : 3 : 3455600
.mp4 : 25 : 200000404
Using total file extension size for sort
.mp4 : 25 : 200000404
.exe : 3 : 3455600
.cpp : 1 : 3400
Here is the code I have so far:
I was thinking of somehow using a class to implement this, but don't know how to go about doing that. Any input will help, thanks for you time.
Using file extension for sort
.cpp : 1 : 3400
.exe : 3 : 3455600
.mp4 : 25 : 200000404
Using total file extension size for sort
.mp4 : 25 : 200000404
.exe : 3 : 3455600
.cpp : 1 : 3400
Here is the code I have so far:
Code:
#include <iostream>
#include <filesystem>
#include <map>
using namespace std;
using namespace std::tr2::sys;
void scan(path f)
{
map<string, int> map;
cout << "Scanning = " << system_complete(f) << endl;
directory_iterator d(f);
directory_iterator e;
for( ; d != e; ++d)
{
path p = d->path();
int temp = file_size(p);
map[extension(p)]++;
}
}
int main(int argc, char* argv[] )
{
path folder = "..";
scan(folder);
return 0;
}