这有效:
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
答案 0 :(得分:14)
问题是sites/test.html
有特殊字符,必须在单引号内。尝试:
file:copy(test.html, 'sites/test.html').
或者您可以使用字符串:
file:copy("test.html", "sites/test.html").
答案 1 :(得分:0)
在erlang中复制/移动它们时,某些大文件会导致问题。使用os:cmd/1
有时更安全。像这样:
move(Source, Destination)-> %% For Windows Command = "MOVE \"" ++ Source ++ "\" \"" ++ Destination ++ "\"", %% For Unix/Linux %%Command = "mv \"" ++ Source ++ "\" \"" ++ Destination ++ "\"", spawn(os,cmd,[Command]).
copy(Source, Destination)-> %% For Windows Command = "XCOPY \"" ++ Source ++ "\" \"" ++ Destination ++ "\"", %% For Unix/Linux %%Command = "cp \"" ++ Source ++ "\" \"" ++ Destination ++ "\"", spawn(os,cmd,[Command]).