On the Mac it's pretty easy to get to a USB drive by name. For example the
following command works if you have a USB drive named "MYUSB"
setwd('/Volumes/MYUSB')
Is there a way to do the same thing in Windows (without knowing the drive
letter)?
Thanks!
[[alternative HTML version deleted]]
Jeff Newmiller
2011-Sep-07 01:36 UTC
[R] Possible to access a USB volume by name in windows
AFAIK the answer is "no". There are ways to look up the volume label
given the drive letter, with which you can search for the drive letter by trial
and error, but in most cases that is more trouble than it is worth.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Gene Leynes <gleynes+r@gmail.com> wrote:
On the Mac it's pretty easy to get to a USB drive by name. For example the
following command works if you have a USB drive named "MYUSB"
setwd('/Volumes/MYUSB')
Is there a way to do the same thing in Windows (without knowing the drive
letter)?
Thanks!
[[alternative HTML version deleted]]
_____________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
Hi,
This comes with absolutely no guarantees (and a good recommendation to
be cautious), but you could try it:
myset <- function(name = "", path = "") {
res <- vector("character", length(LETTERS))
for(i in LETTERS) {
res[i] <- shell(shQuote(paste("VOL ", i, ":", sep =
'')), intern TRUE, ignore.stderr = TRUE)[1L]
}
tmp <- gsub("[[:space:]]", "", grep(name, res,
ignore.case = TRUE,
value = TRUE))
if (!nzchar(tmp)) stop("No volume with ", name, "label name
could be found")
vol <- strsplit(tmp, "drive|is")[[1L]][2L]
fullpath <- paste(vol, ":/", path, sep = '')
cat("Setting WD to ", fullpath, fill = TRUE)
setwd(fullpath)
}
#### Example usage ####
## set WD to root of volume with label "FLASH_NAME"
myset("FLASH_NAME")
## set WD so some subdirectory
myset("FLASH_NAME", "path/to/something")
At least on my system, this takes awhile to run. It iterates through
all the volumes [A-Z], and there will probably be quite a few warnings
unless all volumes are mounted, but the warnings (at least about not
finding drives/bad exit status) should be ignorable.
Cheers,
Josh
On Tue, Sep 6, 2011 at 2:56 PM, Gene Leynes <gleynes+r at gmail.com>
wrote:> On the Mac it's pretty easy to get to a USB drive by name. ?For example
the
> following command works if you have a USB drive named "MYUSB"
> setwd('/Volumes/MYUSB')
>
> Is there a way to do the same thing in Windows (without knowing the drive
> letter)?
>
>
> Thanks!
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/