0

Does any one know where there is some Java code already written to handle deleteing directory trees? Maybe with some undo functions?

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by ceyesuma
0

I'm sure that you can use Google to search for existing code. You can write it by yourself, all the information you need is in the File class.

-1

I'm sure that you can use Google to search for existing code. You can write it by yourself, all the information you need is in the File class.

I did not ask for your opion apines. This forum is to find code not to stroke your ego.
Stating the obvious is not very helpful. I will have code soon that you can learn from. clearly you need this.

Edited by ceyesuma: n/a

Votes + Comments
Show some effort before asking people to do your work for you.
0

Actually this forum is to help and guide with problems and not to do your work for you.

I did not start this post to be inhibited by your chit chat.
I am building the code if you have nothing more.
your post are of no use. I asked if someone knew of the existence of code already written
I did not ask you to write it.

/**
   * Deletes a file or directory, allowing recursive directory deletion. This is an
   * improved version of File.delete() method.
   */
  public static boolean delete(String filePath, boolean recursive) {
      File file = new File(filePath);
      if (!file.exists()) {
          return true;
      }

      if (!recursive || !file.isDirectory())
          return file.delete();

      String[] list = file.list();
      for (int i = 0; i < list.length; i++) {
          if (!delete(filePath + File.separator + list[i], true))
              return false;
      }

      return file.delete();
  }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.