Delete GDB - ArcObjects Java

02-25-2016 10:53 AM
New Contributor II

In an existing Java program I'm troubleshooting, the program creates multiple File GDBs, but doesn't clean them up upon completion or restart of the application.  I'm trying to write some code to have the program delete upon restart.

In my opinion, and I am probably wrong, the way to go would possibly be to grab the Delete function from AbstractGPTool and use it to delete the GDB instead of using a system call to delete it as a file or directory on the network.  I am more accustomed to making, what I refer to as, Toolbox calls via Python and have been unable to find any Java code examples of how to properly set and call this.

if (directory.exists()){

                   //remove it, then create a new one





                   // File directory = new File(reportPath1);



                   //File directory = new File(reportPath1);

public void deleteGDB (String workspace) {
  File gdbFile = new File(workspace);
  Calendar clock1 = Calendar.getInstance();
  long time1 = clock1.getTimeInMillis();
  boolean gdbDelete = gdbFile.delete();
  if (gdbDelete){
System.out.println(workspace + " successfully deleted");
  else {
System.out.println("There was a problem in the delete process.  Renaming ...");
File newName = new File(workspace + time1);
boolean gdbRename = gdbFile.renameTo(newName);
System.out.println("File renamed to " + newName.toString());


Tags (2)
0 Kudos
0 Replies