[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Removing all files from a directory, but not any subdirectories (C++ Sun)

Asked by marcuswork in Unix Systems Programming

Tags: directory, files, all, remove

Hey all, I have a C++ program that is manipulating files in a Unix (sun) directory.  Let's say I have a main_dir and then inside of main_dir are a bunch of files and a temp_dir.  I want to delete all the files "except" for the temp_dir.  Is there a single command I could use to remove "all" files?

main_dir/temp_dir (temp_dir is nested in main_dir along with other files in main_dir)

I've tried doing:
remove("main_dir/*);  // note these are strings converted
                      // into char* pointers in reality
remove("main_dir/*.*"); // by calling my_string.c_str()
system("rm *");

None of these work.  Calling the "system" command gives an error that it can't delete a certain file (usually the first one it tries to delete).  Also, I've tried to use scandir() but get an error that it can't find the include file <sys/dir.h>.  Any help on this would be greatly appreciated.  

Also, after removing all files from main_dir, I'd like to "move" all the files from the nested temp_dir back into the main_dir.  How would I accomplish this in C++ on a Sun machine?  

Thanks,
Marcus
[+][-]11/09/03 05:53 AM, ID: 9709770Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Unix Systems Programming
Tags: directory, files, all, remove
Sign Up Now!
Solution Provided By: yuzh
Participating Experts: 3
Solution Grade: A
 
[+][-]10/30/03 05:30 PM, ID: 9654721Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/03 09:46 AM, ID: 9659143Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/31/03 12:08 PM, ID: 9660158Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/31/03 12:49 PM, ID: 9660417Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 04:29 PM, ID: 9683413Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/03 07:50 PM, ID: 9705655Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/03 06:30 AM, ID: 9706921Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/03 08:34 PM, ID: 9709010Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/03 11:06 AM, ID: 9710769Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/03 05:37 PM, ID: 9711803Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92