r - 为什么 file.exists 尽管位于 list.files 中却返回 FALSE?

标签 r windows file-access

我有一个文件x,它出现在目录中,由list.files证明

x <- "./data-raw/paths/calculate-route-by-FROM-TO/2017-05-2075--FROM-Flinders-Street-Railway-Station--Melbourne-Victoria-3004--VIC--TO-Melbourne-Sports-Aquatic-Centre--30-Aughtie-Dr--Melbourne-VIC-3206--VIC-csv"
x %in% list.files("./data-raw/paths", recursive = TRUE, full.names = TRUE)
# [1] TRUE
file.exists(x)
# [1] FALSE

请注意,x 缺少扩展名,但我在 ?file.exists 中找不到这样的警告:

file.exists returns a logical vector indicating whether the files named by its argument exist. (Here ‘exists’ is in the sense of the system's stat call: a file will be reported as existing only if you have the permissions needed by stat. Existence can also be checked by file.access, which might use different permissions and so obtain a different result. Note that the existence of a file does not imply that it is readable: for that use file.access.) What constitutes a ‘file’ is system-dependent, but should include directories. (However, directory names must not include a trailing backslash or slash on Windows.) Note that if the file is a symbolic link on a Unix-alike, the result indicates if the link points to an actual file, not just if the link exists. Lastly, note the different function exists which checks for existence of R objects.

文档中的唯一提示是访问限制可能会导致 FALSE,并且 file.access(x) 确实是 -1 但我似乎有权访问该文件(以及其他不受影响的非常相似的文件)。

最佳答案

Windows 对文件名长度有上限(260 个字符),x 超出了该上限。缩短文件会导致 file.exists 返回 TRUE

关于r - 为什么 file.exists 尽管位于 list.files 中却返回 FALSE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44159751/

相关文章:

r - ggplot2 中的多个 y 超过 x

C# 文件访问错误

javascript - 在 JavaScript 中打开文件时访问被拒绝错误

r - 将一列数据框逐行合并为一个数据框

r - Debian 测试中的错误 "Unable to find a source package for r-base"

windows - Eclipse、cmake、Windows、MingW - 什么 Makefile 生成器?

linux - 如何在Windows中安装 "Make"命令

asp.net - 拒绝直接访问文件夹(仅允许通过应用程序)

从 R 中的 data.frame 中删除引号 ("")

windows - java 在我的 64 位机器的任务管理器中显示为 32 位