Getting file extensions and file size

Im tyring to just get the file extensions and file size without outputting the file name from any path folder

this is what i have but it gives me the filename + extension when i only want extension
#include <iomanip>
#include <iostream>
#include <locale>
#include <string>
#include <ctime> // ctime_s()
#include <io.h> // _findfirst, etc.
using namespace std;

void scan( string const& filespec, string startDir, bool isRecursive ) {
intptr_t hFile;
_finddata_t fd;

if( !startDir.empty() ) {
char last = startDir.back();
if( last != '/' && last != '\\' && last != ':' )
startDir += '/';
}
string findPath = startDir + filespec;

if( (hFile = _findfirst( findPath.c_str(), &fd )) == -1L ) {
cout << "No " << filespec << " files in current directory.\n";
return;
}

do{
cout << setw(4) << fd.name;
cout << '\t';
cout << setw(4) << fd.size;
cout << '\n';
} while( _findnext( hFile, &fd ) == 0 );
_findclose( hFile );
}





int main( int argc, char* argv[]) {
locale here("");
cout.imbue( here );
scan("*.exe", argv[1], true );
}


Don't make multiple threads about the same problem.
Put your code int [code] tags.
What are the problems with this code?
fd.name is outputing the file names and scan(*.exe is scanning for just file extensions .exe but really waht u want is it to output all the files extensions with no file name just extensions so example

a file has
pic.jpg
statement.exe
blow.ccp

out put wud be
.jpg 200
.exe 532
.ccp 5343

so basically just the extension of file and the file size
fd.name is a c-string I assume?
Then
1
2
3
4
char* get_ext(char* file){
   for(int i = strlen(file)-1; i >= 0; i-- ) if( file[i] == '.' ) return file+i;
   return file;
}
where wud i insert that into the code can u show me where u wud replace it in my code
cout << get_ext(fd.name);
can u show me where in my code u wud put this all cuz when i try add it i get errors so can u just copy paste my code and add that into it
Dear Fanshawe student: do your own homework, and try to get it done in advance of 6 hours before it's due.
ive spent 10 hours tryna figure this shit out, u think i would be askin for help if i could get it
I'm only busting your balls, lol. Thought I could make you think I was the prof. This project is killing me, too.
ive seriously got nothing, i got the filename plsu extension and file size, im failin forsure
Try loading them into a map and doing what you had to do on the last project for the mode, adding up the size and number of extension occurences.

(don't ask me how to code that, I don't know)

and then for output you just need to iterate through the map.
Last edited on
The good news is it's only worth 10%, and you might get part marks for anything you do submit on time.
Topic archived. No new replies allowed.