1

I am using sambal gem for smbclient. I want to create jstree from recursive directory listing from smbclient.

require "sambal"
client = Sambal::Client.new(domain:domain-name, host: host, share: 'all' ,user: 'abc', password: 'pswd')
client.cd("abc")
client.ask("recurse")
all_files_hash = client.ask("ls")

I have modified parse_files method of smbclient to have path in file listing hash. Sample hash of direcory listing that I want to display in JStree:

    all_files_hash = {"."=>{:type=>:directory}, ".."=>{:type=>:directory}, 
    "log"=>{:type=>:directory, :path=>"\\abc"},
     "softwares"=>{:type=>:directory, :path=>"\\abc"}, 
    "test.txt"=>{:type=>:file, :path=>""},
 "test_data"=>{:type=>:directory, :path=>"\\abc"},
 ".keep"=>{:type=>:file, :path=>"\\abc\\log"},
 "alert.log"=>{:type=>:file, :path=>"\\abc\\log"}, 
"development.log"=>{:type=>:file, :path=>"\\abc\\log"},
 "test.log"=>{:type=>:file, :path=>"\\abc\\test_data"},
 "robomongo-0.8.4-x86_64.deb"=>{:type=>:file, :path=>"\\abc\\softwares"}, 
"sublime-text_build-3065_amd64.deb"=>{:type=>:file, :path=>"\\abc\\softwares"},
 "ubuntu"=>{:type=>:directory, :path=>"\\abc\\softwares"},
 "ubuntu.css"=>{:type=>:file, :path=>"\\abc\\softwares\\ubuntu"}} 

How can I create jstree from recursive file listing that I have got in all_files_hash?

Expected Output :

 jstree_hash = [{"text" => "abc","path" => "\\abc","children" => [{"text" => "log","path"=>"\\abc\\log","children" => [{"text" => "development.log","path"=>"\\abc\\log\\developemnt.log"},{"text" => "alert.log","path"=>"\\abc\\log\\alert.log"}]}]}}]

I followed below links but no luck : nested hash and iterate over deep hash

Thanks in advance..

Community
  • 1
  • 1
S R
  • 674
  • 2
  • 18
  • 45
  • take a look at you should take a look at http://stackoverflow.com/a/5523340/1380867 I think this is what you want – MZaragoza Jan 29 '15 at 02:01

0 Answers0