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

    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();
            SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
                    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.

    Thanks,
    Andrew
    Last edited by turanan; 06-16-2009 at 04:37 PM.

Similar Threads

  1. Replies: 3
    Last Post: 01-29-2012, 11:44 AM
  2. Replies: 3
    Last Post: 07-25-2011, 04:19 PM
  3. [SOLVED] Apache Commons Properties file exceptions
    By edwardmluk in forum Java Servlet
    Replies: 1
    Last Post: 03-06-2009, 05: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, 01:29 PM
  5. Replies: 0
    Last Post: 09-13-2008, 08: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
  •