Jump to content




fs.isDir not working? Need Help!


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

#1 Exerro

  • Members
  • 801 posts

Posted 30 August 2012 - 11:53 PM

im making yet another major update for my os which is a complete rewrite and im including a very good filebrowser in it...but i cant get very far with it because fs.isDir doesnt seem to be working.
i have this code:
for i = 1,explorerItemCount do
  if fs.isDir(listOfFiles[i]) then
   writePos((string.len(listOfFiles[i]))+1,4+i,"  - Directory")
  else
   writePos((string.len(listOfFiles[i]))+1,4+i,"  - File")
  end
end
(writePos is a function that is like this function writePos(x,y,text) term.setCursorPos(x,y) term.write(text) end)
when i just start the filebrowser it works fine but if i go into a directory it doesnt work
what it does to get files/dirs is:
function getFiles()
listOfFiles = fs.list(dirViewing)
explorerItemCount = #listOfFiles
end

please help because this is an extremely important part of my os (or will be at least)

#2 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 31 August 2012 - 07:22 AM

try fs.isDir(shell.resolve(filename))

#3 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 31 August 2012 - 07:53 AM

You just need to add in the parent directory into the fs.isDir(). Here's and example..

currentDir = shell.dir()
for i = 1,explorerItemCount do
  if fs.isDir(currentDir.."/"..listOfFiles[i]) then

You can also try

if fs.isDir(shell.resolveProgram(listOfFiles[i]) then

I'm not sure how well it works I've never used it. It might be more robust when dealing with multiple folders in the path.

Edited by luanub, 31 August 2012 - 07:56 AM.


#4 Exerro

  • Members
  • 801 posts

Posted 31 August 2012 - 11:08 AM

oh yeh i cant beleive i missed the parent code :l i feel like such a noob...what is the shall.resolve thing and would it make it possible to get out of just the computer folder?
one more thing is - is there a command like dirViewing.parent or anything that would return the directory that dirViewing is in?

#5 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 31 August 2012 - 11:27 AM

shell.resolve('filename') returns the full path to the specified file or folder so you can use it in most fs and io functions, to go one directory up use fs.setDir(shell.resolve('..'))

EDIT: .. is understood in almost any file system to mean one path up, you need the second because the '' is a special char in Lua, try print('') and you will only get

Edited by KaoS, 31 August 2012 - 11:29 AM.


#6 Exerro

  • Members
  • 801 posts

Posted 31 August 2012 - 11:36 AM

i added this to my code:
elseif key == 13 then
dirViewing = shell.resolve("..")
and it said bluetide:385: Invalid path

#7 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 31 August 2012 - 11:43 AM

I just tried it and it worked fine..... please post the entire code

#8 Exerro

  • Members
  • 801 posts

Posted 31 August 2012 - 11:49 AM

Spoiler
i removed all of the unneccesarry functions and stuff and the reason it has such a wierd setup is so it can draw and run any of the functions and always have the taskbar present and so when in the taskbar it can draw the program without running it





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users