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

fs.list Filters?

Started by danielsv03, 15 April 2017 - 09:01 AM
danielsv03 #1
Posted 15 April 2017 - 11:01 AM
Hello so i was just wondering if it is possible for me to like when i do fs.list i want it too only display folders and not programs. I want too do this because i'm trying to make a program to display all programs but folders in a different color

Thanks¨



SOLVED!
Edited on 15 April 2017 - 11:54 AM
ReBraLaCC #2
Posted 15 April 2017 - 11:05 AM
there is a function in an api, i thought it was fs that gives you a boolean when the file is a directory… i think it is fs.isDirectory(path)
danielsv03 #3
Posted 15 April 2017 - 11:07 AM
Ye i found something like that too its fs.isReadOnly but how could i use that in fs.list?
Lupus590 #4
Posted 15 April 2017 - 11:24 AM

--# use fs.list to get all of the files and folders in the current directory
filesAndFolders = fs.list()

--# for each file and folder check it is a folder
for i = 1, #filesAndFolders do
  if fs.isDirectory(filesAndFolders[i]) then
    table.insert(folders, filesAndFolders[i])
  end
end
Edited on 15 April 2017 - 09:25 AM
danielsv03 #5
Posted 15 April 2017 - 11:25 AM
Thank you Lupus i'ma try it now
danielsv03 #6
Posted 15 April 2017 - 11:38 AM

--# use fs.list to get all of the files and folders in the current directory
filesAndFolders = fs.list()

--# for each file and folder check it is a folder
for i = 1, #filesAndFolders do
  if fs.isDirectory(filesAndFolders[i]) then
	table.insert(folders, filesAndFolders[i])
  end
end

It gave me an error on line 11
Lupus590 #7
Posted 15 April 2017 - 12:15 PM
there isn't a line 11 in my code, so you will need to point out which line is 11 or provide your full code

edit: it might be that folders is nil when i pass it to table.insert, try making an empty table called folders before the for loop
Edited on 15 April 2017 - 10:17 AM
danielsv03 #8
Posted 15 April 2017 - 12:22 PM
Ok i will try

Ok i will try
It didn't give an error but now its blank

I think i can figure that out

Thanks!
danielsv03 #9
Posted 15 April 2017 - 12:45 PM
there isn't a line 11 in my code, so you will need to point out which line is 11 or provide your full code

edit: it might be that folders is nil when i pass it to table.insert, try making an empty table called folders before the for loop

Thanks you for the support now it works!!