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.

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

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

Thanks again for the help. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.