954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Force Delete?

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:

private String destDir = "C:\\temp\\";
    ....
    private void deleteFiles() {
        try {
            Process p = Runtime.getRuntime().exec("del " + destDir + "*.*");
        } catch (IOException e) {
            logger.debug("Can't delete: " + e.getMessage() );
        }
    }


Thanks.

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

Why do you need to run the OS command instead of using File.delete()?

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 
Why do you need to run the OS command instead of using File.delete()?


Thanks again for the help. :-)

new_2_java
Junior Poster
127 posts since Apr 2007
Reputation Points: 7
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You