Jump to content




ListOut Directory on Monitor?

utility

4 replies to this topic

#1 Bertrahm

  • New Members
  • 1 posts

Posted 22 October 2017 - 05:11 AM

Hello,
i wan't to list out an directory on my Monitor i tried the following:
monitor = peripheral.wrap("right")
monitor.clear()
monitor.setTextScale(2)
monitor.setCursorPos(1,1)
local directory = shell.run("dir")
monitor.write(directory)
But then i just get an Boolean, true.
Any help?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 October 2017 - 07:56 AM

shell.run() returns whether the target script executed or not. It doesn't gather terminal output from that script. Calling term.redirect(monitor) and then just doing shell.run("dir") should "work", though.

#3 Stekeblad

  • Members
  • 62 posts
  • LocationSweden

Posted 25 October 2017 - 06:35 AM

monitor right dir
http://www.computerc...onitor_(program)

Edited by Stekeblad, 25 October 2017 - 06:36 AM.


#4 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 25 October 2017 - 11:43 AM

There's also the FS API

#5 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 30 October 2017 - 03:13 PM

View PostLupus590, on 25 October 2017 - 11:43 AM, said:

There's also the FS API
And to extend this: http://www.computerc...fo/wiki/Fs.list
fs.list returns a table, so if you want to print all the files in the directory you need to loop through the table.
--# Find the monitor using peripheral.find
local monitor = peripheral.find( "monitor" )
local sPath   = "/"

--# Setup the monitor
monitor.setTextScale(2)
monitor.setCursorPos(1, 1)
monitor.clear()

--# Redirect all output to the monitor
term.redirect( monitor )

--# Loop through the table and print all the files in the given directory
for _, name in ipairs(fs.list(sPath)) do
     print( name )
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users