Jump to content




fs.isDir() Problem

computer

  • You cannot reply to this topic
8 replies to this topic

#1 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 11 July 2013 - 06: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...



#2 GopherAtl

  • Members
  • 888 posts

Posted 11 July 2013 - 07: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.

#3 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 11 July 2013 - 07:21 PM

I used shell.dir() like

fs.list(shell.dir())

#4 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 11 July 2013 - 07:24 PM

http://imgur.com/HwOia5d

#5 GopherAtl

  • Members
  • 888 posts

Posted 11 July 2013 - 07: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.

#6 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 12 July 2013 - 11:20 AM

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!

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 12 July 2013 - 11:36 AM

Don't directly concatenate paths, use fs.combine instead.

#8 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 12 July 2013 - 01:21 PM

What does that do vs directly concatenating them?

#9 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 12 July 2013 - 06: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.





4 user(s) are reading this topic

0 members, 4 guests, 0 anonymous users