I have a file structure like the following:
-problems
- folder1.1
-folder1.2
-inputFolder
-file.txt1
-file2.txt2
-outputFolder
-file.txt1
-file2.txt2
-folder1.2
-folder2
And I have to convert it into two json objects like this:
problems = {
name: "someNameChosenByMe",
id: "someIdChosenByMe",
tests: {
input: [], // array of strings with contents from text files in input
output: "" // string from files in output
}
}
And this also
tree = [
{
id : "12" id of element from the other json
parent : "someDir" parent directory name
text : "someTextChosenByMe"
icon : "somethingChosenFromMe"
},
{
id : "12" id of element from the other json
parent : "someDir" parent directory name
text : "someTextChosenByMe"
icon : "somethingChosenFromMe"
},
];
... and so on. Basiclly I need to get the content from input and output folders for the first json. And for the second i need the id of the element from the first json and the parent directory. I tried a bunch of things but I don't know what the approach to this is and should be.
$path = 'problems/';
$files = [];
$di = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$it = new RecursiveIteratorIterator($di);
foreach ($it as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) == "txt")
$files[] = $file;
}
This gives me all the possible file paths. But I don't know if I continue this way if it will be best. So what is the approach to this. I dont want any code, just what to do in general. I need the second json to use it for jstree.js. http://www.jstree.com/docs/json