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

File 如何在Erlang中跨目录复制文件?,file,erlang,copy,File,Erlang,Copy,这项工作: 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中跨目录复制文件 非常

这项工作:

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

问题在于
sites/test.html
有特殊字符,必须在单引号内。尝试:

file:copy(test.html, 'sites/test.html').
也可以使用字符串:

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

在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]). 移动(源、目标)-> %%窗户 Command=“移动\+++源+++\”\+++目标+++\”, %%适用于Unix/Linux %%Command=“mv\”“+++源+++”“目标+++”“, 生成(操作系统,命令,[命令]。
复制(源、目标)-> %%窗户 Command=“XCOPY\”++源++“\”++目标++“\”, %%适用于Unix/Linux %%Command=“cp\”“+++源+++”“目标+++”“, 生成(操作系统,命令,[命令])。

不要认为
目标
变量可能包含
正斜杠
反斜杠
,这取决于系统运行的是windows还是unix linux