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

Reading information on disks

Started by firewolf31, 15 January 2014 - 12:39 AM
firewolf31 #1
Posted 15 January 2014 - 01:39 AM
if this has been asked and answered i appaulogize in advance for i have been searching for an hour or 2 and havent found anything about it.

Is is possible to write a program that can read the disk in the disk drive and post it on the screen.

My idea is that i want to be able to have a system then i can click a button on a touchscreen and it will automatically read the programs on a disk and list the programs on the screen as a clickable item to where i can just click the program i want to load onto my computer.

example: the disk label alongtimeago and the disk labeled chat or whatever i want to be able to put them both on a disk sorta thing and then upon inserting a disk in the drive then clicking a button that might say read disk and then it will read the disk and list on the screen as buttons both programs on the disk and when i click say for example alongtimeago it will then start the program on my screen.


thanks in advance for any help i can be given in this idea of mine.

:D/>:D:D:D:D:D:D
Alice #2
Posted 15 January 2014 - 10:22 AM
I'm not sure of the code, but here's the logic behind it.
repeat sleep until detectDisk() == true
get all the programs in there, get there names, then print the names to screen.
Using some button API, make them buttons.
OReezy #3
Posted 15 January 2014 - 11:42 AM
You would use the FS API for this.

www.computercraft.info/wiki/Fs_(API)

fs.list() will return a table with the names of all the files and subdirectories in a directory.

You can use fs.open() to open and read a program and files.

Or if you just want to run the program use shell.run()
www.computercraft.com/wiki/Shell_(API)
Edited on 15 January 2014 - 11:23 AM
firewolf31 #4
Posted 15 January 2014 - 06:13 PM
yeah im looking into reading the programs on the disk and posting them on touchscreen as buttons for sure. So fs.list() would give me a list of files on the disk but how would i specify the floppy disk in drive and not read the programs on the computer itself and also i dont want it to constently look to detect something i will be putting a button that when i click it it will read the disk but i just need to know how to read the disk and post the programs on screen once i click the button. i will be reading that api for sure thanks for the info
OReezy #5
Posted 15 January 2014 - 10:27 PM
You would enter the disk as the directory path for fs.list() which is "/disk"
firewolf31 #6
Posted 16 January 2014 - 11:11 AM
You would enter the disk as the directory path for fs.list() which is "/disk"

yeah i pretty much figured that one out shortly after i wrote the message :D/>.

now i know i probably have to put this listing in a table in order to post it on screen as buttons but heres the next issue im having, im trying to think on how i can determine which program i am clicking on to make sure that it loads the right program on disk.
im guessing i have to use something like for i , #programs do and them button code / function name something something…
albrat #7
Posted 16 January 2014 - 01:44 PM
The table has already done half the job for you. You are calling the filenames from a table and inserting them into buttons…

you already know that the first button is entry 1 in the list table. (buttons on a screen you have to insert a co-ordinate system and names into a table… Just add an additional data element with the program name as well. )

eg. button[1] = { 5, 1, 10, 3, "ButtonsAPI" } –// we have a range of clicking ( x,y 5 pixels in and 1 from the top By 10 pixels and 3 from the top ) and then we store the program name. ( we know this program is on /disk/ so we don't need to store that information. )
The click registers a match on button[1] so we can catch 1 from that and know that button[1][5] is the program that was clicked.
firewolf31 #8
Posted 16 January 2014 - 06:42 PM
The table has already done half the job for you. You are calling the filenames from a table and inserting them into buttons…

you already know that the first button is entry 1 in the list table. (buttons on a screen you have to insert a co-ordinate system and names into a table… Just add an additional data element with the program name as well. )

eg. button[1] = { 5, 1, 10, 3, "ButtonsAPI" } –// we have a range of clicking ( x,y 5 pixels in and 1 from the top By 10 pixels and 3 from the top ) and then we store the program name. ( we know this program is on /disk/ so we don't need to store that information. )
The click registers a match on button[1] so we can catch 1 from that and know that button[1][5] is the program that was clicked.

so something like say

Function loadTitle(name)
   shell.run(name)
end
button.setTable(programName, loadTitle[i], "", xmin, xmax, ymin, ymax )

setTable code in button api :
function setTable(name, func, param, xmin, xmax, ymin, ymax)
   button[name] = {}
   button[name]["func"] = func
   button[name]["active"] = false
   button[name]["param"] = param
   button[name]["xmin"] = xmin
   button[name]["ymin"] = ymin
   button[name]["xmax"] = xmax
   button[name]["ymax"] = ymax
end
im gonna play with this somemore i have a idea i just not sure if it will work yet its in my head and kinda cloudy but thank for your input it does help :D/>
Edited on 16 January 2014 - 05:45 PM
firewolf31 #9
Posted 17 January 2014 - 12:12 PM
fs.list() creates a table of the programs listed on disk now i cant figure out how to take this table and post the information whithin it on to my screen
:(/>
OReezy #10
Posted 17 January 2014 - 02:40 PM
You need to refer to the table it returns. If you have
local tPrograms = fs.list("/path")
then you would refer to the first program in the table as tPrograms[1] and so on. You could also use a for loop to iterate through the table and get them all in one go. One word of advice though, I would check to see if that entry in the table is a subdirectory or not (assuming you only want programs).

This is untested but I am fairly sure this is how the fs.list() works.
firewolf31 #11
Posted 17 January 2014 - 08:21 PM
You need to refer to the table it returns. If you have
local tPrograms = fs.list("/path")
then you would refer to the first program in the table as tPrograms[1] and so on. You could also use a for loop to iterate through the table and get them all in one go. One word of advice though, I would check to see if that entry in the table is a subdirectory or not (assuming you only want programs).

This is untested but I am fairly sure this is how the fs.list() works.

yea i created a small test program and this is the code

local data = fs.list("disk")
for i = 1, #data do
	 print (data[i])
end

and to be honnest i dont know what i was doing wrong last night for it didnt work for me but today i tried it again and it listed what i had on the disk
do its works

now i just have to add it in button form in my actual program and hope that works :D/>

thanks guys im getting somewhere:D

PS.. how would i take this list and make it list 12 programs per page and have them listed in 2 columns

ive already got a paging system working all i need to do now is post the information in as 12 names per page which means 6 names per columns per page

im trying to decipher an other code but the one i am looking it is for comunication with turtles and chest and mystcraft books

and i cant quit decipher it :S
Edited on 18 January 2014 - 12:57 AM
OReezy #12
Posted 18 January 2014 - 03:51 AM
im trying to decipher an other code but the one i am looking it is for comunication with turtles and chest and mystcraft books

If this is the Direwolf20 code, from what I've heard it's notoriously hard to use due to bad programming practices. I haven't touched buttons yet, but here is a button API I've heard good things about.

http://www.computerc..._hl__touchpoint
firewolf31 #13
Posted 18 January 2014 - 03:59 AM
im trying to decipher an other code but the one i am looking it is for comunication with turtles and chest and mystcraft books

If this is the Direwolf20 code, from what I've heard it's notoriously hard to use due to bad programming practices. I haven't touched buttons yet, but here is a button API I've heard good things about.

http://www.computerc..._hl__touchpoint

yes it is the direwolf20 code but its not the button code im having issues with its the portal code he uses and what i want to duplicate is adding the programs in 2 columns with a set number of programs per page
note that i am also learning lua as i am doing this so i aint the best but i understand good and learn quick