开发者

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

开发者 https://www.devze.com 2023-03-18 08:56 出处:网络
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

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 }
0

精彩评论

暂无评论...
验证码 换一张
取 消