Reputation: 6259
I wrote this code:
verz = 'C:\Users\GerdPC\Desktop\mouth'
Dir.foreach(verz) do |f|
next if f == '.' or f == '..'
puts f
end
My problem is that I don't know how to return not only the filename f
for eg:
sumba.png
But:
C:\Users\GerdPC\Desktop\mouth\sumba.png
So I tried:
puts File.expand_path(f)
But this only expands the filename with the directory in which my program is running! What should I do?
Upvotes: 1
Views: 1054
Reputation: 118261
I would do it as below using File::realdirpath
:
Dir.pwd # => "/home/kirti/Ruby"
Dir.foreach(Dir.pwd) do |file|
puts File.realdirpath(file) unless ['.','..'].include? file
end
# >> /home/kirti/Ruby/tut.html
# >> /home/kirti/Ruby/test
#.........
#.........
Upvotes: 2