20 posts
Posted 30 March 2012 - 03:13 PM
Hello. I make a OS. Must copy directory.
Copy directory code fragment:
fs.copy("diskmine" "mine")
I tried
os.copy("diskmine" "mine")
Not works :o/>/>
In 1 line of code I put: fs.makeDir("mine")
Error is: No such file.
Please help.
473 posts
Location
Poland
Posted 30 March 2012 - 03:33 PM
i don't think you can copy a directory, but i will try to get something to help you.
Edit: Here you go, this should copy sub-directories as well.
Spoiler
function copyDir(a,:o/>/>
local list=fs.list(a)
fs.makeDir(:o/>/>
for i=1, #list, 1 do
if fs.isDir(a..list[i]) then copyDir(a..list[i],b..list[i])
else fs.copy(a..list[i],b..list[i]) end
end
return true
end
1604 posts
Posted 30 March 2012 - 07:01 PM
What's the problem with fs.copy() ? It can copy directories (at least it works for me).
161 posts
Posted 01 April 2012 - 06:51 AM
I'm pretty sure path components are separated by forward slashes in ComputerCraft, not backslashes. Even if backslashes are acceptable, you would need to double them in a string literal like this because in Lua, backslash is used as an escape character (this problem doesn’t occur with forward slashes, so they’re easier to use either way).