Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list files based on a pattern in a specific directory - one command only

Tags:

ruby

I can make it work this way

Dir.chdir(basedir)
puts Dir.glob("#{filename}*").inspect

Is there any way to do so using only one command? I want to list

  • all files that stat with filename
  • the the directory basedir

Update 1

puts "#{csv_dir_name}\\#{testsuite}*"
puts Dir["#{csv_dir_name}\\#{testsuite}*"].inspect

retuns

C:\Program Files\TestPro\TestPro Automation Framework\Output Files\builds\basics\logs\basics\2011\07\07114100\login*
[]

on the other hand, this code works fine

Dir.chdir(csv_dir_name)
csv_file_name = Dir.glob("#{testsuite}*")
like image 443
Radek Avatar asked Sep 12 '25 08:09

Radek


1 Answers

I think this should do what you want:

puts Dir["#{basedir}/#{filename}*"]

Or alternatively:

puts Dir["#{File.join(basedir, filename)}*"]

like image 103
Paul Prestidge Avatar answered Sep 13 '25 21:09

Paul Prestidge