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

fs help

Started by ETHANATOR360, 07 August 2012 - 01:02 AM
ETHANATOR360 #1
Posted 07 August 2012 - 03:02 AM
is there a way to read all the files of a certain type in a directory and send the information over the rednet
ETHANATOR360 #2
Posted 07 August 2012 - 03:04 AM
i also need to read the variables in the file once one has been selected over the rednet
wilcomega #3
Posted 07 August 2012 - 03:10 PM
you sghould really try it first before asking others
KFAFSP #4
Posted 07 August 2012 - 03:18 PM
You can get a full Listing by :

local Listing = fs.list(<PATH>)
If you then iterate through the Listing, checking if the entry is a file or dir, you can detect alle Files in that dir.
You will need to user recursion if you want to process subdirs too.

Reading Variables from a File is rather easy :


local tEnv = {}
os.run(tEnv, <PATH>)
-- Get a Var with name <NAME>
local Var = tEnv[<NAME>]

This only works, when the file you are reading is in LUA. To prevent errors, use :

pcall(os.run, tEnv, <PATH>)

If you want a full Directory-Listing Function, you may checkout my klib-API Package,
File : klib_files
Functions : ListEx, ListExR
ETHANATOR360 #5
Posted 07 August 2012 - 03:42 PM
ok thanks, and can you give me a link to your api
KFAFSP #6
Posted 07 August 2012 - 04:22 PM
Goto : http://www.computercraft.info/forums2/index.php?/topic/3140-api-rednet-ms-style-domain-controllers-and-os/

In the first post, open the Downloads section spoiler, and click the >>DOWNLOAD<< Link. Save the .zip and extract it. The API you need is in /apis/generic/klib_files. It requires a function from /apis/generic/klib_util, but you may CopyPaste that into this file, assuming you dont want to install the whole Package.

In case you do want to, read the Installation section.