2 posts
Posted 20 February 2013 - 10:38 AM
Hi, how would I go about copying all files from a computer into its own folder on a floppy with a LUA program? I was thinking about using the fs.copy action, but I see no way to copy all files with it. Sorry for the nooby question, still new to LUA. Thanks in advance :)/>/>
8543 posts
Posted 20 February 2013 - 11:14 AM
Split into new topic.
You'll want to iterate through the table returned by fs.list() and use fs.copy() on each file.
871 posts
Posted 20 February 2013 - 11:19 AM
fs.copy will copy a file or directory, and you can loop over the files in a directory with fs.list, so…
--ignore list - keys in this table cover what won't be copied
--the "true" is meaningless, this is just a handy way to lookup keys quickly
local ignore={
disk=true,
rom=true,
--anything else you don't want copied add here.
}
--list everything in root folder...
for _,filename in fs.list("")
--only stuff not in ignore list
if not ignore[filename] then
--copy
fs.copy(filename,"disk/"..filename)
end
end
This assumes a single disk drive, with disk already inserted, and won't overwrite if same-named files exist on the disk already.
2088 posts
Location
South Africa
Posted 20 February 2013 - 06:02 PM
fs.copy will copy a file or directory, and you can loop over the files in a directory with fs.list, so…
--ignore list - keys in this table cover what won't be copied
--the "true" is meaningless, this is just a handy way to lookup keys quickly
local ignore={
"disk"=true,
"rom"=true,
--anything else you don't want copied add here.
}
--list everything in root folder...
for _,filename in fs.list("")
--only stuff not in ignore list
if not ignore[filename] then
--copy
fs.copy(filename,"disk/"..filename)
end
end
This assumes a single disk drive, with disk already inserted, and won't overwrite if same-named files exist on the disk already.
local ignore = {
['disk'] = true,
['rom'] = true,
}
I don't think you can do it like "disk"=true
871 posts
Posted 20 February 2013 - 06:10 PM
ahem. You're right, thanks. Should've been "["disk"]=true" or just "disk=true". Fixed.
15 posts
Posted 14 November 2013 - 02:04 PM
13: 'do' expected
What did I do wrong?
1852 posts
Location
Sweden
Posted 14 November 2013 - 02:16 PM
The line with a for loop should have a do
for _, filename in fs.list("") do
15 posts
Posted 14 November 2013 - 04:55 PM
--ignore list - keys in this table cover what won't be copied
--the "true" is meaningless, this is just a handy way to lookup keys quickly
local ignore={
["disk"]=true,
["rom"]=true,
["cpdf"]=true,
--anything else you don't want copied add here.
}
--list everything in root folder...
for _,filename in fs.list("") do
--only stuff not in ignore list
if not ignore[filename] then
--copy
fs.copy("disk/"..filename,filename)
end
end
Tryed copy from disk to root like this:
but got: 11: attempt to call table
1852 posts
Location
Sweden
Posted 14 November 2013 - 06:23 PM
Well change the line with the for loop to this
for _, filename in ipairs(fs.list("")) do
That should fix it ;)/>