Gabor Grothendieck
2014-Jan-17 05:10 UTC
[Rd] file.exists does not like path names ending in /
If a path name ends in slash then file.exists says it does not exist. I would have expected these to all return TRUE.> file.exists("/Program Files")[1] TRUE> file.exists("/Program Files/")[1] FALSE> file.exists(normalizePath("/Program Files/"))[1] FALSE> R.version.string[1] "R version 3.0.2 Patched (2013-11-25 r64299)" I am using Windows 8.1 . -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On 17.01.2014 06:10, Gabor Grothendieck wrote:> If a path name ends in slash then file.exists says it does not exist. > I would have expected these to all return TRUE. > >> file.exists("/Program Files") > [1] TRUE >> file.exists("/Program Files/") > [1] FALSE >> file.exists(normalizePath("/Program Files/")) > [1] FALSE >> R.version.string > [1] "R version 3.0.2 Patched (2013-11-25 r64299)" > > I am using Windows 8.1 . >See ?file.exists: "(However, directory names must not include a trailing backslash or slash on Windows.)" Note also that "/Program Files" is not safe anyway since it is relative to the current drive. Best, Uwe Ligges
Martin Maechler
2014-Jan-17 11:16 UTC
[Rd] file.exists does not like path names ending in /
>>>>> Gabor Grothendieck <ggrothendieck at gmail.com> >>>>> on Fri, 17 Jan 2014 00:10:43 -0500 writes:> If a path name ends in slash then file.exists says it does > not exist. I would have expected these to all return > TRUE. >> file.exists("/Program Files") > [1] TRUE >> file.exists("/Program Files/") > [1] FALSE >> file.exists(normalizePath("/Program Files/")) > [1] FALSE >> R.version.string > [1] "R version 3.0.2 Patched (2013-11-25 r64299)" I would also have expected all these to work, but that is only because I do not use Windows; indeed, for me (Linux Fedora 19, but I'm pretty sure *any* version): > dir.create("/tmp/foo bar") > normalizePath("/tmp/foo bar/") [1] "/tmp/foo bar" > file.exists("/tmp/foo bar/") [1] TRUE > file.exists(normalizePath("/tmp/foo bar/")) [1] TRUE > > I am using Windows 8.1 . poor you ;-) yes, don't take it personally Last but not least ?file.exists in its 'Details' section mentions several times how Windows behaves differently from the civilized world (:-) notably that it also says (However, directory names must not include a trailing backslash or slash on Windows.) So, all seems as documented, but unfortunately your (and most probably not only yours !!) expectations are different. I agree that this is quite unfortunate, and we all would be happy if OSes were consistent here. I wonder if R couldn't help you (and many others) better to gloss over these OS differences in a helpful way. This list may be a good place to discuss such proposals ... Martin -- Martin Maechler ETH Zurich -- and R Core Team
Seemingly Similar Threads
- Proposed change in file.exists() to tolerate Windows
- Inconsistant result for normalizePath on Windows
- UNC windows path beginning with backslashes: normalizePath bug??
- Suggestion/opinions: add a `absolute` param to `normalizePath()` to force returning an absolute path
- normalizePath is sometimes very slow for nonexistent UNC paths