3

这有效:

1> file:copy(test.html, test1.html).
{ok,2384}

但这不会:

2> file:copy(test.html, sites/test.html). 
   ** exception error: bad argument in an arithmetic expression
   in operator  '/'/2
   called as sites / 'test.html'

如何在 Erlang 中跨目录复制文件?

非常感谢,

LRP

4

2 回答 2

14

问题是sites/test.html具有特殊字符并且必须在单引号内。尝试:

file:copy(test.html, 'sites/test.html').

或者你可以使用字符串:

file:copy("test.html", "sites/test.html").
于 2012-08-01T21:26:55.900 回答
0

当您在 erlang 中复制/移动它们时,一些大文件会导致问题。有时使用起来更安全os:cmd/1。像这样:

移动(来源,目的地)->
    %% 对于 Windows
    命令 = "MOVE \"" ++ 源 ++ "\" \"" ++ 目的地 ++ "\"",
    %% 对于 Unix/Linux
    %%Command = "mv \"" ++ 源 ++ "\" \"" ++ 目标 ++ "\"",
    产生(操作系统,cmd,[命令])。
复制(来源,目的地)-> %% 对于 Windows 命令 = "XCOPY \"" ++ 源 ++ "\" \"" ++ 目标 ++ "\"", %% 对于 Unix/Linux %%Command = "cp \"" ++ 源 ++ "\" \"" ++ 目标 ++ "\"", 产生(操作系统,cmd,[命令])。

于 2012-08-03T08:51:26.153 回答