Force Delete?

Thread Solved

Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Force Delete?

 
0
  #1
Jan 31st, 2008
Hi all,

I want to run an OS command from my Java code. Basically I want to delete an unknown number of file from a particular directory from my Java code (in windows). But the way "del *.*" commnad works it prompts you whether you want to delete it or not. How can I delete those temp files without answering "y"es to the prompt from my code?

Please advise...

Here's what I tried:
  1. private String destDir = "C:\\temp\\";
  2. ....
  3. private void deleteFiles() {
  4. try {
  5. Process p = Runtime.getRuntime().exec("del " + destDir + "*.*");
  6. } catch (IOException e) {
  7. logger.debug("Can't delete: " + e.getMessage() );
  8. }
  9. }

Thanks.
Last edited by new_2_java; Jan 31st, 2008 at 1:57 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,454
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 511
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Force Delete?

 
0
  #2
Jan 31st, 2008
Why do you need to run the OS command instead of using File.delete()?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 126
Reputation: new_2_java is an unknown quantity at this point 
Solved Threads: 6
new_2_java new_2_java is offline Offline
Junior Poster

Re: Force Delete?

 
0
  #3
Jan 31st, 2008
Originally Posted by Ezzaral View Post
Why do you need to run the OS command instead of using File.delete()?

Thanks again for the help. :-)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC