Created
November 16, 2016 20:18
-
-
Save Dulani/e34f747b7f47d9a9537c0a236db1f907 to your computer and use it in GitHub Desktop.
R helper functions for performing WebDAV tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(curl) | |
library(XML) | |
listFiles <- function(username, password, relPath = "/", dav = "https://dav.box.com/dav") { | |
uri <- URLencode(paste(dav, relPath, sep="")) | |
# fetch directory listing via curl and parse XML response | |
h <- new_handle() | |
handle_setopt(h, customrequest = "PROPFIND") | |
handle_setopt(h, username = username) | |
handle_setopt(h, password = password) | |
response <- curl_fetch_memory(uri, h) | |
text <- rawToChar(response$content) | |
doc <- xmlParse(text, asText=TRUE) | |
# calculate relative paths | |
base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="") | |
result <- unlist( | |
xpathApply(doc, "//d:response/d:href", function(node) { | |
sub(base, "", URLdecode(xmlValue(node)), fixed=TRUE) | |
}) | |
) | |
result[result != ""] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment