David Whyte

Greenhorn
+ Follow
since Apr 29, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Whyte

Hi,
I'm new to Java & I have the following java app (below) which I need to deploy on a Tomcat server and call automatically from a JSP prior to writing files from a database. The app basically deletes all files of a certain extension and thus prevents old data from clogging up the server.
Therefore 2 questions:
1.) In order for this to work, how must I implement it as a server-side app?
2.) How can I invoke it automatically each time a user wants to write a file from the database? (I already have auto-reloading activated in Tomcat).

public class delfile {
public static void main (String args[]) {
delfile td = new delfile();
td.deleteFiles("C:/Tomcat/jakarta-tomcat-5.0.18/webapps/ROOT/", ".xml");
}
public void deleteFiles( String d, String e ) {
ExtensionFilter filter = new ExtensionFilter(e);
File dir = new File(d);
String[] list = dir.list(filter);
File file;
if (list.length == 0) return;
for (int i = 0; i < list.length; i++) {
file = new File(d + list[i]);
boolean isdeleted = file.delete();
System.out.print(file);
System.out.println( " deleted " + isdeleted);
}
}
class ExtensionFilter implements FilenameFilter {
private String extension;
public ExtensionFilter( String extension ) {
this.extension = extension;
}
public boolean accept(File dir, String name) {
return (name.endsWith(extension));
}
}
}

Thanks,
David
[ April 29, 2004: Message edited by: David Whyte ]
19 years ago