-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand files into multiple new ones #51
Comments
If you return a new Example with the former: julia> ft= maketree(["a" => [(name="b", value=1), (name="c", value=2)]])
./
└─ a/
├─ b (Int64)
└─ c (Int64)
julia> mapsubtrees(ft, r"b") do node
return ft
end
./
└─ a/
├─ a/
│ ├─ b (Int64)
│ └─ c (Int64)
└─ c (Int64)
``´ |
In my case this didn't quite work because I don't want to replace a MWE: julia> tree = maketree(["folder" => [(name = "file", value = "value")]])
./
└─ folder/
└─ file (5-codeunit String)
julia> map(tree, dirs = false) do file
maketree([(name = "file $i", value = i) for i in 1:4])
end
./
└─ folder/
└─ ./
├─ file 1 (Int64)
├─ file 2 (Int64)
├─ file 3 (Int64)
└─ file 4 (Int64) |
Hi, You can specify the name of the root of you put is as the very first argument (note that the array starts at after the julia> newtree = map(tree, dirs = false) do file
maketree(name(file) => [(name = "file $i", value = i) for i in 1:4])
end
./
└─ folder/
└─ file/
├─ file 1 (Int64)
├─ file 2 (Int64)
├─ file 3 (Int64)
└─ file 4 (Int64) If you don't want the julia> mv(newtree, r"file/", s"")
./
└─ folder/
├─ file 1 (Int64)
├─ file 2 (Int64)
├─ file 3 (Int64)
└─ file 4 (Int64)
|
Fwiw, here is the function I use in my own code to do this in one go. As you can tell from the name and usage, it requires one to think a bit carefully when using it: julia> mapleavesparent(f, ft) = map(ft) do node
# NOTE: Only applies when all children are files. What does the user want to do if there is a mix of Files and FileTrees?
eltype(children(node)) === File ? f(node) : node
end;
julia> mapleavesparent(tree) do node
# Just don't forget that "file" is the child of node, not node itself
maketree(name(node) => [(name = "file $i", value = i) for i in 1:4])
end
./
└─ folder/
├─ file 1 (Int64)
├─ file 2 (Int64)
├─ file 3 (Int64)
└─ file 4 (Int64)
|
I think ./
└─ folder/
└─ ./
├─ file 1 (Int64)
├─ file 2 (Int64)
├─ file 3 (Int64)
└─ file 4 (Int64) Should behave equivalently to ./
└─ folder/
├─ file 1 (Int64)
├─ file 2 (Int64)
├─ file 3 (Int64)
└─ file 4 (Int64) Or maybe there should be a function which turns the former into the latter. |
I couldn't quite figure out how to do this: I have a bunch of audio files and want to do four transformations on each of them, resulting in four separate files per original file. I don't think I can map over the files and return multiple new files each, or maybe that works with mapsubtrees? I'm not sure
The text was updated successfully, but these errors were encountered: