2012-06-14 29 views
2

我發現,有可能使用下面的命令來打開Windows資源管理器經由cmd.exe程序的預定路徑:打開窗口使用系統命令與特定路徑探險

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 \被替換爲只有一個。

當我複製粘貼從警告消息的資源管理器C:\ Users \ xxx位到cmd.exe程序時,資源管理器在指定路徑中打開。

有沒有人知道爲什麼會失敗?

回答

5

嘗試

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

您好!那工作。非常感謝!我只是將我的Mac OS R更新爲2.15.0,但似乎Mac版本沒有shell命令... – user969113

+0

在MacOS下,您可以使用system(「open/Applications /」)等 – Hansi

0

我創建這個簡單的功能...我希望這將是有用的!

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

簡而言之:它需要當前目錄,更改斜槓方向並調用cmd.exe來打開它。問候。