Program to Delete Files in a Given Directory
import java.io.File;
/**
* Program to delete files in a directory.
*
* @author vsphanindra
*/
public class DeleteDirectory {
public static void function (File dir,String a){
String[] info = dir.list();
for (int i = 0; i < info.length; i++) {
File n = new File(a + dir.separator + info[i]);
if (!n.isFile())
continue;
System.out.println("Removed:" + n.getPath());
if (!n.delete())
System.err.println("Couldn't remove:" + n.getPath());
}
}
public static void main(String[] argv) {
if (argv.length != 1) {
System.err.println("Enter in this format :::-------- java Empty DeleteDirectory and its path ");
System.exit(1);
}
File dir = new File(argv[0]);
if (!dir.exists()) {
System.out.println(argv[0] + " Directory does not exist");
return;
}
function(dir,argv[0]);
}
}
/* javac DeleteDirectory.java */
/* java DeleteDirectory pathofthedirectory */
/**
* Program to delete files in a directory.
*
* @author vsphanindra
*/
public class DeleteDirectory {
public static void function (File dir,String a){
String[] info = dir.list();
for (int i = 0; i < info.length; i++) {
File n = new File(a + dir.separator + info[i]);
if (!n.isFile())
continue;
System.out.println("Removed:" + n.getPath());
if (!n.delete())
System.err.println("Couldn't remove:" + n.getPath());
}
}
public static void main(String[] argv) {
if (argv.length != 1) {
System.err.println("Enter in this format :::-------- java Empty DeleteDirectory and its path ");
System.exit(1);
}
File dir = new File(argv[0]);
if (!dir.exists()) {
System.out.println(argv[0] + " Directory does not exist");
return;
}
function(dir,argv[0]);
}
}
/* javac DeleteDirectory.java */
/* java DeleteDirectory pathofthedirectory */