« Home | Program to Write to a file » | Program to Rename Files in a given Directory » 

Monday, March 06, 2006 

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 */

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com