-3

This is how I am changing the directory path to the download folder.

Dir.chdir("C:/Users/abcd/Downloads/")

But this specific to a user. Is there is any way to make it more general?

Hope1234
  • 13
  • 7
  • 1
    https://stackoverflow.com/questions/9416578/relative-path-to-your-project-directory Is the best I can do without being able to see your attempted code – Dean Coakley Mar 09 '18 at 11:44
  • Possible duplicate of [Relative path to your project directory](https://stackoverflow.com/questions/9416578/relative-path-to-your-project-directory) – Pieter Herroelen Mar 09 '18 at 14:57

2 Answers2

2

Use home method for Dir

Dir.chdir(Dir.home + '/Downloads')
Ashik Salman
  • 1,819
  • 11
  • 15
1

The "C:/Users/abcd/Downloads/" looks like the user directory for user abcd on windows. So I think this is a windows related question.

The Dir.home on my Windows-PC is U:/, not the user-directory.

But you can make use of ENV:

Dir.chdir(File.join(ENV['USERPROFILE'], 'Downloads'))

Just to be aware of: This changes the directory for the rest of your script. There is also a block-version of Dir.chdir.

knut
  • 27,320
  • 6
  • 84
  • 112