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:
|
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