1 2 import java.awt.*; 3 import java.awt.event.*; 4 import javax.swing.*; 5 import java.io.*; 6 7 void DeleteFiles(String sExt, String sPath){ 8 File fDirectory = new File(sPath); 9 File[] aFile= fDirectory.listFiles();//list all files in directory 10 11 for( int i=0; i<aFile.length; i++){// loop through content of directory 12 if(aFile[i].isFile()){ //check if its a file 13 String sFile= aFile[i].toString(); //gets a string 14 sFile= sFile.toLowerCase(); // set it to lowercase 15 if( sFile.endsWith(sExt) ==true){ //check if the file ends with extention 16 aFile[i].delete(); //deletes file 17 } 18 } 19 } 20 } 21 22 23 void jButton2_actionPerformed(ActionEvent e) { 24 25 //Call to delete files use lowercase for sending mask 26 DeleteFiles(".txt","C:\\Test\\"); 27 28 } 29