使用系统命令打开具有特定路径的Windows资源管理器

问题描述 投票:2回答:2

我发现可以使用以下命令通过cmd.exe程序使用预定义路径打开Windows资源管理器:

explorer PATH 

使用以下命令返回R打开Windows资源管理器:

system("explorer", intern=TRUE) 

但是,当我指定路径时,R将返回以下警告消息,并且不会在指定路径处打开资源管理器:

> system("explorer C:\\Users\\xxx", intern=TRUE) 
character(0) 
attr(,"status") 
[1] 1 
Warning message: 
running command 'explorer C:\Users\xxx' had status 1 

我引用了\其他R抱怨没有从\ Users识别\ U.

但是,当执行命令时,我们希望double \只替换为一个。

当我将R警告消息中的资源管理器C:\ Users \ xxx位复制粘贴到cmd.exe程序时,将在指定的路径中打开资源管理器。

有没有人知道为什么会失败?

r system
2个回答
5
投票

尝试

shell("explorer C:\\Users\\xxx", intern=TRUE) 

0
投票

我已经创建了这个简单的功能...我希望它会有用!

wopen <- function(x){
  y <- getwd()
  y <- gsub("/", "\\\\", y)
  shell(paste0("explorer ", y), intern = TRUE) 
}

简而言之:它采用当前目录,更改斜杠方向并调用cmd.exe将其打开。问候。

© www.soinside.com 2019 - 2024. All rights reserved.