10 posts
Posted 18 June 2014 - 10:23 PM
how would i say 'All' like I want to delete 'All' created programs and I want to copy 'All' programs from a floppy?
fs.delete()
40 posts
Posted 18 June 2014 - 10:38 PM
This code will delete all files AND folders on the computer:
for i,v in ipairs(fs.list("/")) do fs.delete(v) end
The fs.list("/") returns a list of files and folders in the root of the drive.
Using the above code as base you can transmute it into copy and the floppy thingy.
WARNING: Deletes all files and folders if you run it!!! (of course the ROM folder is safe!)
Hope this helps - And sorry i do not take time to answer your question more detailed!
/sEi
EDIT: typos
Edited on 18 June 2014 - 08:41 PM
3790 posts
Location
Lincoln, Nebraska
Posted 18 June 2014 - 10:46 PM
In general, you'd want to use pairs for the file list, cause ipairs can have problems without numbered indexes.
for k,v in pairs(fs.list("/")) do fs.delete(v) end
for k,v in pairs(fs.list("disk")) do fs.copy(v, "/"..v) end
Edited on 18 June 2014 - 09:22 PM
1281 posts
Posted 18 June 2014 - 10:55 PM
The table fs.list returns is infact numerically indexed, so using ipairs is the best choice.
10 posts
Posted 18 June 2014 - 11:14 PM
In general, you'd want to use pairs for the file list, cause ipairs can have problems without numbered indexes.
for k,v in pairs(fs.list("/")) do fs.selete(v) end
for k,v in pairs(fs.list("disk")) do fs.copy(v, "/"..v) end
Im not familer with these…
I see the for loop but what is
k, v
for?
Along with
in pairs
&
"/"
1852 posts
Location
Sweden
Posted 18 June 2014 - 11:20 PM
In general, you'd want to use pairs for the file list, cause ipairs can have problems without numbered indexes.
for k,v in pairs(fs.list("/")) do fs.selete(v) end
for k,v in pairs(fs.list("disk")) do fs.copy(v, "/"..v) end
Maybe you should add
fs.isReadOnly()? Otherwise it'll error :P/>
Edit: Also want to point out that you wrote
fs.selete
Edited on 18 June 2014 - 09:47 PM
3790 posts
Location
Lincoln, Nebraska
Posted 18 June 2014 - 11:22 PM
k and v are variables i am assigning to "k"eys and "v"alues of the table returned from pairs. using "for _ in pairs()" will iterate through a table defined in the parentheses, and do the commands you pass to it after the do command.
When I tell fs.list() to use "/" as the variable, it will search in that directory, in this case, the lowest directory available, which is the root directory.
Maybe you should add fs.readOnly()? Otherwise it'll error :P/>
Edit: Also want to point out that you wrote fs.selete
It should still delete all other files just fine, then error out. Also, bleh, spelling.