Hello!
I'm building a plugin in which I would like to iterate through files inside a folder of the 'data' folder in Oxide. The problem is that given its sandboxed nature and restricted I/O, I cannot use C#'s 'Directory.GetFiles()' method to iterate through all the files and get their names, so that I would later open one of them. In order to keep track of the files I have to manually hardcode them or keep an extra file that stores information about these files, but given that this gets really sloppy in terms of code quality and is in general not my favorite approach (to a simple I/O operation), I would like to ask if there is any way to get the names of all files in a directory using Oxide.
Not much information is available and all that currently led to is making an 'Extension'.
Thank you for your time!
Solved List files in sub-directory within '/data' folder?
Discussion in 'Rust Development' started by TeamRequem, Sep 10, 2016.
-
Wulf Community Admin
What is the purpose of messing with another plugin's data file?
-
It's not that. In the data folder I would have a sub-directory in which I have files, each file containing generated data. Since files would be dynamically added/removed from the folder, what I want to do is to be able to then call a function which iterates through the filenames, stores them in an array and with the help of a System.Random object grab one of the filenames, which is later used to load that specific file.
And depending on implementation, that file could have information about entity locations, spawnpoints, gear sets and similar. -
If your plugin is in charge of creating these files, then you can add the file name to a list when creating it and storing that list in a data file to keep track of the list.
-
Yeah, that's currently how I'm managing the files, although it would ruin the portability of the plugin a bit, since if I were to copy files from another machine, I would also have to go through manually adding the names to the database. Same for removal not through the plugin.
-
Wulf Community Admin
If your plugin creates the filenames, they should be the same between machines. You can easily create a list of what files are being made and the dynamically make those as well, all from within your plugin with no additional changes being needed. -
Well yeah, those are workarounds but can get more conplicated than necessary. I work by the KISS principle, so that's why I asked. In that case regarding the question, I should take it as impossible to list files within a directory and instead need to have an abstract version of the folder, so I can iterate through the filenames?
-
Wulf Community Admin
I don't see how that would be more complicated, it's a simple list. You'd be naming the files as you normally would anyways, just storing them in a separate list that is then later used to create those same files. It wouldn't really be much more (if not less) than the code than the way you want to do it.
You won't be able to use i/o like you want via a plugin due to the sandboxing, it's there to prevent files being touched and tossed everywhere. -
Well not necessarily but I understand what you mean. It is good to keep it sandboxed, beyond any doubt after all.
Thank you for the replies, I got the answer I was looking for! ^^
