Difference between revisions of "Fs.list"
From ComputerCraft Wiki
(Add a description) |
Zalerinian (Talk | contribs) (Made the cod easier to read and added an explanation of it.) |
||
| Line 5: | Line 5: | ||
|api=fs | |api=fs | ||
|returns=[[table (type)|table]] list of files and folders in <var>path</var>, which must be a directory | |returns=[[table (type)|table]] list of files and folders in <var>path</var>, which must be a directory | ||
| − | |desc=Returns a list of all the files contained in a directory | + | |desc=Returns a list of all the files contained in a directory as a table |
|examples= | |examples= | ||
{{Example | {{Example | ||
| − | |desc=Displays a list of all files and folders in the root directory of a computer | + | |desc=Displays a list of all files and folders in the root directory of a computer as a table |
| − | |code= | + | |code=abc = fs.list("") |
| − | + | i = 1 | |
| − | + | while i ~= nil do | |
| − | |output=A list of all files and folders in the root directory | + | print(abc[i]) |
| + | i = i+1 | ||
| + | end | ||
| + | |||
| + | |output=A list of all files and folders in the root directory as a table | ||
}} | }} | ||
}} | }} | ||
| + | |||
| + | abc = fs.list("") <- will get all the files and directories in the system root into a table, all saved as 'abc'. | ||
| + | i = 1 <- sets i equal to one. | ||
| + | while i ~= nil do <- While i isn't nil, continue to do this. | ||
| + | print(abc[i]) <- print the files and directories. | ||
| + | i = i+1 <- add 1 to i each run so a different file/directory gets listed next. | ||
| + | end <- end the loop. | ||
Revision as of 15:29, 27 May 2012
| Returns a list of all the files contained in a directory as a table | |
| Syntax | fs.list(string path) |
| Returns | table list of files and folders in path, which must be a directory |
| Part of | ComputerCraft |
| API | fs |
Examples
abc = fs.list("") <- will get all the files and directories in the system root into a table, all saved as 'abc'. i = 1 <- sets i equal to one. while i ~= nil do <- While i isn't nil, continue to do this. print(abc[i]) <- print the files and directories. i = i+1 <- add 1 to i each run so a different file/directory gets listed next. end <- end the loop.