Apr 15, 2011 at 5:38pm UTC
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 );
}
Apr 15, 2011 at 6:12pm UTC
Don't make multiple threads about the same problem.
Put your code int [code] tags.
What are the problems with this code?
Apr 15, 2011 at 6:19pm UTC
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
Apr 15, 2011 at 6:32pm UTC
where wud i insert that into the code can u show me where u wud replace it in my code
Apr 15, 2011 at 8:42pm UTC
cout << get_ext(fd.name);
Apr 15, 2011 at 10:10pm UTC
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
Apr 15, 2011 at 10:33pm UTC
Dear Fanshawe student: do your own homework, and try to get it done in advance of 6 hours before it's due.
Apr 15, 2011 at 10:40pm UTC
ive spent 10 hours tryna figure this shit out, u think i would be askin for help if i could get it
Apr 15, 2011 at 10:42pm UTC
I'm only busting your balls, lol. Thought I could make you think I was the prof. This project is killing me, too.
Apr 15, 2011 at 10:44pm UTC
ive seriously got nothing, i got the filename plsu extension and file size, im failin forsure
Apr 15, 2011 at 10:46pm UTC
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 Apr 15, 2011 at 10:47pm UTC
Apr 15, 2011 at 10:54pm UTC
The good news is it's only worth 10%, and you might get part marks for anything you do submit on time.