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

fs.isDir() Problem

Started by LNETeam, 11 July 2013 - 05:48 PM
LNETeam #1
Posted 11 July 2013 - 07:48 PM
Hey guys! I recently started a project for a file browser and it is coming along good, but I have hit an awkward bump. I have written the program out and have obviously not finished yet, but an important functionality is failing. The part that is not working is folder creation and recognition. My browser is designed to show you which file listings are folder and which are files. The way that works is through fs.isDir(). I passes a table of fs.list() through that part of the function and it seperates them depending on data type. The only problem is it is not recognizing the folders that ARE folders as in you can see they are in the terminal. Code: http://pastebin.com/uuYMsp7R. Please help me as I have been stuck and can't move on without it…

GopherAtl #2
Posted 11 July 2013 - 08:04 PM
are you giving full paths? because fs.list doesn't return full paths automatically; detType(fs.list("rom")), for example, would not identify any directories, unless you had directories in root with the same names as things in rom.
LNETeam #3
Posted 11 July 2013 - 08:21 PM
I used shell.dir() like

fs.list(shell.dir())
LNETeam #4
Posted 11 July 2013 - 08:24 PM
http://imgur.com/HwOia5d
GopherAtl #5
Posted 11 July 2013 - 08:42 PM
apparently you completely failed to understand my post.

what you passed in to fs.list is irrelevant, except that passing in "" or "/" for the root dir would work, while any other directory would not.

fs.list returns just the names of items in the directory, ex, fs.list("rom") will return {"apis","help","programs","startup"} on a blank computer. fs.isDir("help") on that same computer will return false, because "/help" doesn't exist, and so can't be a directory. fs.isDir("rom/help") will return true, because /rom/help does exist, and is a directory.
LNETeam #6
Posted 12 July 2013 - 12:20 PM
Thank you for helping me! It's fine now. I used fs.isDir(shell.dir().."/"..v) where v is the file/folder being checked. It works fine now!
Lyqyd #7
Posted 12 July 2013 - 12:36 PM
Don't directly concatenate paths, use fs.combine instead.
LNETeam #8
Posted 12 July 2013 - 02:21 PM
What does that do vs directly concatenating them?
Lyqyd #9
Posted 12 July 2013 - 07:43 PM
It ensures that even if you get a path with a trailing / (like foo/bar/), it won't concatenate it to foo/bar//baz.