Jump to content




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


  • You cannot reply to this topic
4 replies to this topic

#1 campicus

  • Members
  • 164 posts

Posted 14 October 2013 - 07: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!

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 October 2013 - 07: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


#3 campicus

  • Members
  • 164 posts

Posted 14 October 2013 - 08: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


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 October 2013 - 08:23 PM

You need to change both 1s and remove the quotes around that first table reference.

#5 steelstiletto

  • New Members
  • 1 posts

Posted 15 October 2013 - 01:49 AM

Here's what I have:

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






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users