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

ListOut Directory on Monitor?

Started by Bertrahm, 22 October 2017 - 04:11 AM
Bertrahm #1
Posted 22 October 2017 - 06: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?
Bomb Bloke #2
Posted 24 October 2017 - 08: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.
Stekeblad #3
Posted 25 October 2017 - 07:35 AM
monitor right dir
http://www.computercraft.info/wiki/Monitor_(program)
Edited on 25 October 2017 - 05:36 AM
Lupus590 #4
Posted 25 October 2017 - 12:43 PM
There's also the FS API
TheOddByte #5
Posted 30 October 2017 - 03:13 PM
There's also the FS API
And to extend this: http://www.computercraft.info/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