Your question is quite difficult to fulfill.
list.dirs will return (by default) the path relative to the current working directory.
If you change the working directory, the relative paths will not be valid.
You can try using full.names = TRUE in the .dirs list, in which your temp function returns the working directory to its original state
temp <- function(path) { owd <- getwd() on.exit(setwd(owd)) print(path) setwd(path) print(getwd()) }
An even better idea is, instead of messing around with the working directory, just pass the appropriate xmlParse file xmlParse (or whatever your function does)
files <- list.files(pattern = '\\.xml$', recurvise = TRUE) XML <- lapply(files, xmlParse)
mnel
source share