[RELEASE] File Manager Device

Oh that’s easy, that line is about all it takes to implement a fileTrimTop, full function would look like:

def fileTrimTop(fname, trimOffset){
   fileData = readFile(fname)
   writeFile(fname, fileData.substring(trimOffset)
}
1 Like

I've been trying [unsuccessfully] to get Google Charts to read and plot a data set using html and csv files on my HE. I had basically abandoned the idea because I thought it would be impractical to manually "manage" the source data file when it got too long. Your driver seems to be able to solve that problem. The next hurdle is pulling that data into a google charts object. The documentation says it's possible, but I'm not a programmer so the developer docs might as well be written in ancient Sanskrit...

1 Like

v0.1.0 changes:

  • Added temporary fileContent attribute (erases after 30 seconds - plenty of time for automation to process); if you use this option it is recommended that you set Event and State history for this device to 1 (no need to store the file in the file system and twice in the database).
  • Added fileList attribute
  • Added fileTopTrim command to allow the removal of the first X characters in the file
  • Added copyFile command to allow copying one local file to another
1 Like

v0.1.0 should allow you to do this via:

* execute the readFile command

  • assign attribute fileContent to a variable
  • add data, sort, etc.
  • writeFile from the variable

New webCoRE functionality (as of 30Mar22) natively lets you:

  • read file into $file variable
  • set variable to $file + new content
  • sort, etc.
  • write file back out from variable
3 Likes

v0.2.0 Adds a callback option for apps that want to use this as an addon device instead of a child device, i.e.

input "fileDev", "capability.actutator", title: "Select File Device", required: true, submitOnChange: true

Using this option, implementation on the app side will look similar to:

def retVal    
fileDev.readFile("someFile.txt") {cb ->
       retVal = cb
}

Shoutout to @gopher.ny for pointing out this option to me.

3 Likes

@Pantheon latest release of webCoRE now incorporates file read/write/append/exist natively:

2 Likes

Awesome!! Thanks for the heads up.

v0.2.2 corrects the retrieval of text files that have embedded extended characters, i.e. characters that use umlauts etc.

1 Like

v0.2.3 Adds the ability to read and upload image files

2 Likes

Can your driver create folders so the root is not too messy?

Doesn’t appear to be supported..

In RM, how do i access the file contents?
Driver page works great.
How do I get it into a string to manipulate with RM?

It should place the return of a read into the attribute fileContent, which should be available under the Custom Attributes.

Where am I going wrong?

I change the contents of the file, RM shows null.
Device works in device tab.

I thought I had it!

Did you do a readFile to load the attribute? (It clears the attribute after 30 seconds BTW.)

Added a line, readfile, same result.

1 Like

Not sure why RM doesn’t like it but


RM has it’s own read/write/append such that the first action should yield the same result as the what should occur by combining actions 2 & 3 (which don’t seem to load the variable even if you introduce a delay)

Found the issue, on line 47 change

attribute "fileContents", "string"

to

attribute "fileContent", "string"
2 Likes

Bingo!
Thanks for this driver, it has great potential.
Off to experiment with it.

2 Likes

Getting unexpected responded, and error.