list files based on a pattern in a specific directory - one command only
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_n开发者_运维问答ame}\\#{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}*")
I think this should do what you want:
puts Dir["#{basedir}/#{filename}*"]
Or alternatively:
puts Dir["#{File.join(basedir, filename)}*"]
previous working directory is restored when the command executed:
Dir.chdir(basedir) { puts Dir.glob("#{filename}*").inspect }
精彩评论