<p>So I was given the task of putting about 200k files into a tree of nested folders. Basically there will be a folder with 100 folders in it with each folder also having 100 folders each. So the tree would have a height of about 4. Iv looked at the go documentation for the mkdir and mkdirall functions but I'm still not sure where to go with that. I'm not asking for the code to achieve this, just some guidance on where I should begin or what kind of concepts to research more. </p>
<p>Thanks</p>
<hr/>**评论:**<br/><br/>kris-nova: <pre><p>What is the end goal here? I don't understand what we need to do with all these folders. It sounds like we need to create them. If so you could make a recursive tree walker that would create a directory at each node. </p>
<p>It would be helpful if we knew the context and any restraints here. Do you need to do this once? Once a second? </p>
<p>Do you need to do this based on some sort of naming convention? If so do we know the names and how they fit together?</p></pre>lroe: <pre><p>Well I wasn't given much, all that I was told was to make the tree of folders then place the files in the folders of the bottom row of nodes. I'll look into the recursive tree walker, thank you. I just have one question, how would I make each node have 100 children? Do I just have 100 pointers in my tree struct?</p></pre>kris-nova: <pre><p>I prefer to use a tree where each node has a list of children. Some people might argue a tree composed of linked lists might be better, or at least make for a better academic exercise. </p>
<p>Here is an example of a tree composed of nodes, each with a list of children, and how to walk through it. <a href="https://play.golang.org/p/r2N1V2FvOZ" rel="nofollow">https://play.golang.org/p/r2N1V2FvOZ</a></p>
<p>Also for reference here is the source code to an article I wrote a while back. The article is gone, but I think the source is still valuable. Note in this example the tree is processed concurrently so that might be a little bit more involved then what you are going for. <a href="https://github.com/Nivenly/nivenly.com/blob/master/examples/go/concurrent_digraph_processing.go" rel="nofollow">https://github.com/Nivenly/nivenly.com/blob/master/examples/go/concurrent_digraph_processing.go</a></p>
<p>Does this help?</p></pre>lroe: <pre><p>Yeah that helps a lot, thank you very much :)</p></pre>kris-nova: <pre><p>Glad it helped. It was a good exercise, I went ahead and dropped the source code off here in a write up. I know it's not exactly what you are looking for, but it's a good tree demo. <a href="https://www.nivenly.com/single-rooted-tree-in-go/" rel="nofollow">https://www.nivenly.com/single-rooted-tree-in-go/</a></p></pre>fhjfgfhfhfhftyjfghft: <pre><p>I'd argue a linked list is a tree, and that linking trees in a certain way(linearly) produces a linked list.</p></pre>kris-nova: <pre><p>I think semantically that's 100% correct. I just usually think of a linked list as having a "next" instead of a "parent" or "child". So it's really just the way I am thinking about it. Also aren't linked lists typically a single node connecting to another single node? A tree would then be a case where a single node can connect to N other nodes.</p></pre>fhjfgfhfhfhftyjfghft: <pre><p>Trees are complex. Trees in this context would be <a href="https://en.wikipedia.org/wiki/Tree_(data_structure)" rel="nofollow">https://en.wikipedia.org/wiki/Tree_(data_structure)</a>. Linked lists have a degree of one.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传