get file size EURGENT!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 48
Reputation: Argo54325 is an unknown quantity at this point 
Solved Threads: 0
Argo54325 Argo54325 is offline Offline
Light Poster

get file size EURGENT!!

 
0
  #1
Apr 1st, 2009
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)

  1. #include <iomanip>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. #include <boost/filesystem.hpp>
  8. #include <boost/filesystem/fstream.hpp>
  9. using namespace boost::filesystem;
  10.  
  11. #include <boost/regex.hpp>
  12.  
  13. void show_files_withR( const path & directory, bool recurse_into_subdirs = true)
  14. {
  15. if( exists( directory ) )
  16. {
  17. directory_iterator end ;
  18. for( directory_iterator iter(directory) ; iter != end ; ++iter )
  19. if ( is_directory( *iter ) )
  20. {
  21. cout << "\nd: " << setw(5) << right << iter->path() ;
  22. if( recurse_into_subdirs ) show_files_withR(*iter) ;
  23. }
  24. else
  25. cout << "\n-: " << setw(5) << right << iter->path() ;
  26. }
  27. }
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31. if (argc != 4)
  32. {
  33. cout << "Usage: program.exe [switches] [path] [filespec]" << endl;
  34. }
  35. else
  36. {
  37. string s_switches(argv[1]);
  38. string s_path(argv[2]);
  39. string s_filespec(argv[3]);
  40.  
  41. bool aSwitch = false;
  42. bool rSwitch = false;
  43. bool RSwitch = false;
  44. bool lSwitch = false;
  45.  
  46. //set switches
  47. if (s_switches == "-a")
  48. {
  49. bool aSwitch = true;
  50. cout << "switch -a is: " << aSwitch << endl;
  51. }
  52. if (s_switches == "-r")
  53. {
  54. bool rSwitch = true;
  55. cout << "switch -r is: " << rSwitch << endl;
  56. }
  57. if (s_switches == "-R")
  58. {
  59. bool RSwitch = true;
  60. cout << "switch -R is: " << RSwitch << endl;
  61. }
  62. if (s_switches == "-l")
  63. {
  64. bool lSwitch = true;
  65. cout << "switch -l is: " << lSwitch << endl;
  66. }
  67.  
  68. //boost::regex expr(s_filespec);
  69. //fs::path currentPath(s_path);
  70. //cout << currentPath << endl;
  71. //fs::basic_directory_iterator(s_path);
  72.  
  73.  
  74. //uintmax_t file_size(const path&)
  75.  
  76. const path & directory = s_path;
  77. if( exists( directory ) )
  78. {
  79. directory_iterator end;
  80. for( directory_iterator iter(directory) ; iter != end ; ++iter )
  81. if ( is_directory( *iter ) )
  82. {
  83. cout << "\nd: " << setw(5) << right << file_size(s_path) << iter->path();
  84. if(RSwitch) show_files_withR(*iter);
  85. }
  86. else
  87. cout << "\n-: " << setw(5) << right << iter->path();
  88. }
  89.  
  90. }
  91.  
  92. cin.ignore();
  93. return 0;
  94. }
Last edited by Argo54325; Apr 1st, 2009 at 9:51 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 181
Reputation: adam1122 is an unknown quantity at this point 
Solved Threads: 28
adam1122 adam1122 is offline Offline
Junior Poster

Re: get file size EURGENT!!

 
0
  #2
Apr 1st, 2009
What are the errors?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 48
Reputation: Argo54325 is an unknown quantity at this point 
Solved Threads: 0
Argo54325 Argo54325 is offline Offline
Light Poster

Re: get file size EURGENT!!

 
0
  #3
Apr 1st, 2009
adam, do u have msn or something? it would be a hell of a lot easier to talk over that, my email is <snipped>

as for the error its a debug error saying it crashed on runtime in an unusual way.
Last edited by Ancient Dragon; Apr 1st, 2009 at 11:59 pm. Reason: snipped email
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 181
Reputation: adam1122 is an unknown quantity at this point 
Solved Threads: 28
adam1122 adam1122 is offline Offline
Junior Poster

Re: get file size EURGENT!!

 
0
  #4
Apr 1st, 2009
Getting some food right now.

Use some print statements in your code to figure out where you are getting errors.

I'll try to help when I get back but I have some work to do so I'll only be able to stop in here when I feel like procrastinating.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 48
Reputation: Argo54325 is an unknown quantity at this point 
Solved Threads: 0
Argo54325 Argo54325 is offline Offline
Light Poster

Re: get file size EURGENT!!

 
0
  #5
Apr 1st, 2009
i know for sure its the file_size() thats causing the error, i just took it out and it runs fine
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 181
Reputation: adam1122 is an unknown quantity at this point 
Solved Threads: 28
adam1122 adam1122 is offline Offline
Junior Poster

Re: get file size EURGENT!!

 
1
  #6
Apr 1st, 2009
You're passing file_size the root directory path. I don't know that it will accept a directory. I don't think so. You should probably only use it if it's is a file and use this: iter->path()
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 48
Reputation: Argo54325 is an unknown quantity at this point 
Solved Threads: 0
Argo54325 Argo54325 is offline Offline
Light Poster

Re: get file size EURGENT!!

 
0
  #7
Apr 1st, 2009
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
Last edited by Argo54325; Apr 1st, 2009 at 11:31 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 181
Reputation: adam1122 is an unknown quantity at this point 
Solved Threads: 28
adam1122 adam1122 is offline Offline
Junior Poster

Re: get file size EURGENT!!

 
0
  #8
Apr 2nd, 2009
I don't know what you are asking. Verbosity is a good thing when asking a technical question. You should probably have a function for each of the switches but you need to list what each is for. Can there be multiple switches?
Last edited by adam1122; Apr 2nd, 2009 at 12:03 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 48
Reputation: Argo54325 is an unknown quantity at this point 
Solved Threads: 0
Argo54325 Argo54325 is offline Offline
Light Poster

Re: get file size EURGENT!!

 
0
  #9
Apr 2nd, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 181
Reputation: adam1122 is an unknown quantity at this point 
Solved Threads: 28
adam1122 adam1122 is offline Offline
Junior Poster

Re: get file size EURGENT!!

 
0
  #10
Apr 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC