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

Getting A Programs Of A Dir And Putting Them In A Table

Started by campicus, 14 October 2013 - 06:31 PM
campicus #1
Posted 14 October 2013 - 08:31 PM
Hi all,

this is probably uber simple and I have searched through the forums and google but couldn't find anything…

Basically, I want to be able to put all programs from a directory into a folder. I want to do this because I basically have a folder with updated programs, I want to move these programs to another directory.

e.g.,

local allPrograms = {}
--"code to get the list of programs (from "/camp/updates/") here and put them in allPrograms"

for i,v in ipairs(allPrograms) do
  fs.copy("allPrograms[1]", "/camp/"..allPrograms[1])
end

All help is appreciated!
Bomb Bloke #2
Posted 14 October 2013 - 08:46 PM
fs.list

You would also need to change your copying loop somewhat, as its current state only inspects the first table element and a pre-made string. fs.move may also be more suitable depending on whether you want to keep the excess copies.

for i,v in ipairs(allPrograms) do
  fs.copy("/sourcefolder/"..v, "/camp/"..v)
end
campicus #3
Posted 14 October 2013 - 09:10 PM
fs.list… duh… haha thanks for the info!

Oops, typo in my code. Was meant to be:


for i,v in ipairs(allPrograms) do
  fs.copy("allPrograms[i]", "/camp/"..allPrograms[1])
end
Bomb Bloke #4
Posted 14 October 2013 - 09:23 PM
You need to change both 1s and remove the quotes around that first table reference.
steelstiletto #5
Posted 15 October 2013 - 02:49 AM
Here's what I have:

for __, v in pairs(fs.list("/camp/updates/")) do
  fs.copy("/camp/updates/"..v, "/camp/"..v)
end