| | |
get file size EURGENT!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 48
Reputation:
Solved Threads: 0
I've been trying all night to get this to work, but everything i do give me a compile or runtime error.
currently I'm using file_size() (no idea what to include inside the brackets).
Also if you have can help with any of the following it would help me greatly:
-list the files in reverse order
-show all files (including hidden files)(dont know if its doing that now, if so then i need to switch it so its off by default)
-how to display the filename (example.txt)
currently I'm using file_size() (no idea what to include inside the brackets).
Also if you have can help with any of the following it would help me greatly:
-list the files in reverse order
-show all files (including hidden files)(dont know if its doing that now, if so then i need to switch it so its off by default)
-how to display the filename (example.txt)
C++ Syntax (Toggle Plain Text)
#include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> using namespace boost::filesystem; #include <boost/regex.hpp> void show_files_withR( const path & directory, bool recurse_into_subdirs = true) { if( exists( directory ) ) { directory_iterator end ; for( directory_iterator iter(directory) ; iter != end ; ++iter ) if ( is_directory( *iter ) ) { cout << "\nd: " << setw(5) << right << iter->path() ; if( recurse_into_subdirs ) show_files_withR(*iter) ; } else cout << "\n-: " << setw(5) << right << iter->path() ; } } int main(int argc, char *argv[]) { if (argc != 4) { cout << "Usage: program.exe [switches] [path] [filespec]" << endl; } else { string s_switches(argv[1]); string s_path(argv[2]); string s_filespec(argv[3]); bool aSwitch = false; bool rSwitch = false; bool RSwitch = false; bool lSwitch = false; //set switches if (s_switches == "-a") { bool aSwitch = true; cout << "switch -a is: " << aSwitch << endl; } if (s_switches == "-r") { bool rSwitch = true; cout << "switch -r is: " << rSwitch << endl; } if (s_switches == "-R") { bool RSwitch = true; cout << "switch -R is: " << RSwitch << endl; } if (s_switches == "-l") { bool lSwitch = true; cout << "switch -l is: " << lSwitch << endl; } //boost::regex expr(s_filespec); //fs::path currentPath(s_path); //cout << currentPath << endl; //fs::basic_directory_iterator(s_path); //uintmax_t file_size(const path&) const path & directory = s_path; if( exists( directory ) ) { directory_iterator end; for( directory_iterator iter(directory) ; iter != end ; ++iter ) if ( is_directory( *iter ) ) { cout << "\nd: " << setw(5) << right << file_size(s_path) << iter->path(); if(RSwitch) show_files_withR(*iter); } else cout << "\n-: " << setw(5) << right << iter->path(); } } cin.ignore(); return 0; }
Last edited by Argo54325; Apr 1st, 2009 at 9:51 pm.
•
•
Join Date: Feb 2009
Posts: 48
Reputation:
Solved Threads: 0
ya funny, i just got it to work as you posted that... anyways i'm having a little problem printing out the sub directories. and ideas why?
EDIT: actually is there another way to do the "process all folders recursively" part without using an outside method, i can't assign switch variables to the method due to it not being inside the main class. so can you show me how to add it on to the one inside the class
EDIT: actually is there another way to do the "process all folders recursively" part without using an outside method, i can't assign switch variables to the method due to it not being inside the main class. so can you show me how to add it on to the one inside the class
Last edited by Argo54325; Apr 1st, 2009 at 11:31 pm.
•
•
Join Date: Feb 2009
Posts: 48
Reputation:
Solved Threads: 0
There is a function i have at the top it is being used to go into sub directory's. For some reason it isn't working now, I wanted to have the whole program work within the "main" class. So i need that function at the top to be worked into the one inside the class. Also it is possible to have more then one switch at a time, so if that happens, then i would want to turn on the features inside that one loop. This cannot be done if its outside of the main (as far as i know).
Clear things up?
Clear things up?
•
•
Join Date: Mar 2009
Posts: 181
Reputation:
Solved Threads: 28
I think you are going in the wrong direction. You should be creating functions, like your show_files_withR function, instead of integrating it into your main function (classes are a very different thing).
What does each of the switches do? You can pass switches as parameters to your function, if you need access to them in there.
What does each of the switches do? You can pass switches as parameters to your function, if you need access to them in there.
![]() |
Similar Threads
- file size (C++)
- File size in C (Win32) (C)
Other Threads in the C++ Forum
- Previous Thread: Read This Before Posting
- Next Thread: Class Problem
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





