This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TechnicalCoding's profile picture

List all folders but no files from a directory in program

Started by TechnicalCoding, 12 June 2016 - 08:26 PM
TechnicalCoding #1
Posted 12 June 2016 - 10:26 PM
Look at title!

I have been searching for hours please help
Emma #2
Posted 12 June 2016 - 10:31 PM
use fs.list in conjunction with fs.isDir (isDirectory)

function listFolders(directory)
	local all = fs.list(directory)
	local tab = {}
	for i=1,#all do
		if fs.isDir( fs.combine(directory, all[i] ) ) then
			table.insert(tab, all[i])
		end
	end
	return tab
end
Edited on 13 June 2016 - 12:19 AM
Bomb Bloke #3
Posted 13 June 2016 - 02:08 AM
You may need to change a line:

if fs.isDir( fs.combine(directory, all[i] ) ) then
Emma #4
Posted 13 June 2016 - 02:19 AM
You may need to change a line:

if fs.isDir( fs.combine(directory, all[i] ) ) then

Ahh thanks, slipped my mind. :P/>
Edited.