This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kreezxil's profile picture

Access Denied When Do Fs.copy

Started by kreezxil, 14 September 2013 - 09:08 AM
kreezxil #1
Posted 14 September 2013 - 11:08 AM
I am having a weird issue, I am getting an access denied error on line 47 of the following http://pastebin.com/240tXAJA

Spoiler

--[[
Name: masscopy
Description: Allows you to copy all of the files in one directory to another
Author: Kreezxil 
Date: 9/14/2013
]]--

args = { ... }

if #args == 0 then
    print("Usage: ")
    print("  masscopy <source> <destination>")
    print("")
    print("  where <source> and <destination> are both directories.")
end

if args[1] ~= nil then
    source = shell.resolve(args[1])
    if not fs.isDir(source) then
        print("Error! Invalid source directory specified. Try again.")
        return
    end
end

if args[2] ~= nil then
    dest = shell.resolve(args[2])
    if not fs.isDir(dest) then
        print("Creating destination directory " .. dest)
        fs.makeDir(dest)
    end
end

list = fs.list(source)

for _,file in ipairs(list) do
    exists=false
    if fs.exists(dest .. "/" .. file) then
        exists=true
        print("File " .. file .. " exists at destination! Overwrite? (y/n)")
        ans = read()
        if string.find("Yy",ans) ~= nil then
            exists=false
            fs.delete(dest .. "/" .. file)
        end
    end
    if not exists then
        fs.copy("/" .. source .. "/" .. file,dest) -- line 47
        print("Copying file " .. file .. " to " .. dest)
    else
        print("Not Copying file " .. file .. " to " .. dest .. " per your instructions.")
    end
end

print("Done Copying!")
Yevano #2
Posted 14 September 2013 - 11:30 AM
The fs.copy function expects the full name of the copied file to be included in the dest path. That is to say, fs.copy("/a/test", "/b") does not copy test into the directory b. Instead, use fs.copy("/a/test", "/b/test").
kreezxil #3
Posted 14 September 2013 - 01:55 PM
The fs.copy function expects the full name of the copied file to be included in the dest path. That is to say, fs.copy("/a/test", "/b") does not copy test into the directory b. Instead, use fs.copy("/a/test", "/b/test").

Thanks man, that solved the problem! :)/>