3

I use JRuby in SikuliX IDE to get list of folders and its subfolders recursively and store its absolute paths(which may contains also dotted characters) in an array. I tried to use following code:

records = Dir.glob 'C:/_private/Files/**/*/'

I got error message:

[error] SyntaxError ( invalid multibyte char (UTF-8) )

Expected output:

C:/_private/Files/dir1
C:/_private/Files/dir1/subdir1
C:/_private/Files/dir1/subdir2
C:/_private/Files/dir2
C:/_private/Files/dir2/subdir1
C:/_private/Files/dir2/subdir2
plaidshirt
  • 5,189
  • 19
  • 91
  • 181

3 Answers3

3

please check new stuff it producing expected result -

 records = Dir.glob('/E:/ISSUE_Folder/**/*.*')

 records.each do |item|
   puts File.dirname(item)
 end

enter image description here

As you see its going to every folder and sub folder

EugZol
  • 6,476
  • 22
  • 41
Kandy
  • 673
  • 9
  • 21
1

My rails app have config folder & it have number of files & subfolders, so getting only folders in config,

I used ap below provided by awesome_print gem

> ap Dir.glob "#{Rails.root}/config/**/"
[
    [0] "/home/ray/projects/example_app/config/",
    [1] "/home/ray/projects/example_app/config/initializers/",
    [2] "/home/ray/projects/example_app/config/locales/",
    [3] "/home/ray/projects/example_app/config/environments/"
]

I have test folder inside config/locales/, It is also got by following query.

> ap Dir.glob "#{Rails.root}/config/**/**/"
[
    [0] "/home/ray/projects/example_app/config/",
    [1] "/home/ray/projects/example_app/config/initializers/",
    [2] "/home/ray/projects/example_app/config/locales/",
    [3] "/home/ray/projects/example_app/config/locales/test/",
    [4] "/home/ray/projects/example_app/config/environments/"
]

For further search for sub-folders on third level hierarchy, I will use "#{Rails.root}/config/**/**/**/"

Update:

You can try with following for windows,

irb(main):022:0> Dir.glob("D:/sd/*/")  # first hierarchy 
=> ["D:/sd/df/", "D:/sd/dff/"]   

irb(main):023:0> Dir.glob("D:/sd/*")
=> ["D:/sd/351px-Nvidia_logo.png", "D:/sd/df", "D:/sd/dff"]

irb(main):024:0> Dir.glob("D:/sd/*/*/") # second hierarchy
=> ["D:/sd/dff/ty/"]

irb(main):025:0> Dir.glob("D:/sd/*/*")
=> ["D:/sd/df/351px-Nvidia_logo2.png", "D:/sd/dff/ty"]

You can further get result by adding first and second hierarchy (commented in above) subfolders

ray
  • 5,454
  • 1
  • 18
  • 40
1

Maybe your JRuby be using less than or equal to ruby 1.9

In Ruby 1.9, the header in your file needs to indicate encoding format.

Add this line at top

# encoding: UTF-8

ogelacinyc
  • 1,272
  • 15
  • 30