0

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.

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by new_2_java
0

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

Thanks again for the help. :-)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.