Results 1 to 1 of 1
  1. #1
    turanan is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default apache commons vfs delete directory with dependancies

    I'm new to vfs and I want to know how I can remove a directory, which is not empty.

    The following code seems to remove single files and empty directories quite easily:

    Java Code:
        public void testRemoveRemoteFile() throws FileSystemException {
            FileSystemOptions fsOptions = new FileSystemOptions();
                    fsOptions, "no");
            DefaultFileSystemManager fsManager = (DefaultFileSystemManager) VFS.getManager();
            if (fsManager.resolveFile("sftp://user:pass@host/remotepath/", fsOptions).exists()) {
                fsManager.resolveFile("sftp://user:pass@host/remotepath/", fsOptions).delete();
                System.out.println("File removed successfully");
    But I want my code to be able to remove directories, which have files or sub-directories in them. The spec says, that we should use fileObject.delete(FileSelector); instead of fileObject.delete();
    but so far I haven't been able to use this method, as I don't know what this FileSelector type parameter should contain. If anyone has encountered this problem, please post an example, which removes non-empty files.

    Last edited by turanan; 06-16-2009 at 03:37 PM.

Similar Threads

  1. Replies: 3
    Last Post: 01-29-2012, 10:44 AM
  2. Replies: 3
    Last Post: 07-25-2011, 03:19 PM
  3. [SOLVED] Apache Commons Properties file exceptions
    By edwardmluk in forum Java Servlet
    Replies: 1
    Last Post: 03-06-2009, 04:24 PM
  4. [SOLVED] To Delete All subdir in a directory
    By tOpach in forum New To Java
    Replies: 3
    Last Post: 11-18-2008, 12:29 PM
  5. Replies: 0
    Last Post: 09-13-2008, 07:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts