Difference between revisions of "Fs.list"

From ComputerCraft Wiki
Jump to: navigation, search
m
Line 11: Line 11:
 
|code=local FileList = fs.list("") --Table with all the files and directories available
 
|code=local FileList = fs.list("") --Table with all the files and directories available
 
   
 
   
  for _,file in ipairs( FileList ) do --Loop. Underscore because we don't use the key, ipairs so it's in order
+
  for _, file in ipairs(FileList) do --Loop. Underscore because we don't use the key, ipairs so it's in order
   print( file ) --Print the file name
+
   print(file) --Print the file name
 
  end --End the loop
 
  end --End the loop
  

Revision as of 18:05, 2 December 2012


Grid Redstone.png  Function fs.list
Returns a list of all the files contained in a directory, in table format
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

Grid paper.png  Example
Displays a list of all files and folders in the root directory of a computer
Code
local FileList = fs.list("") --Table with all the files and directories available

for _, file in ipairs(FileList) do --Loop. Underscore because we don't use the key, ipairs so it's in order
  print(file) --Print the file name
end --End the loop
Output A list of all files and folders in the root directory as a table. Note that fs.list() could also be inserted directly into ipairs() or pairs(). Using pairs would list hidden files as ipairs would not.