Are you trying to change the filenames using Dir and File.rename on Mac OS?

advertisements

I'm following a tutorial and am trying to change the names of three files in a folder that's located under 'drive/users/myname/test'. I'm getting the error:

'chdir': No such file or directory - test'.

The starting path is already 'drive/users/myname', which is why I thought that I only had to enter 'test' for Dir.chdir.

How do I correctly input the paths on Mac OS?

Dir.chdir('test')

pic_names = Dir['test.{JPG,jpg}']

puts "What do you want to call this batch"
batch_name = gets.chomp
puts
print "Downloading #{pic_names.length} files:  "

pic_number = 1
pic_names.each do |p|
  print '.'
  new_name = "batch_name#{pic_number}.jpg"

  File.rename(name, new_name)
  pic_number += 1
end


I think you have to provide the absolute path. So, your first line should be:

Dir.chdir("/drive/users/myname/test")

According to the documentation:

Dir.chdir("/var/spool/mail")
puts Dir.pwd

should output/var/spool/mail.

You can look at the documentation for more examples.