How to run cd command / change folder path from ruby ​​script

I am trying to run a command from a ruby ​​script. I am stuck in changing the folder path. Below is the command I wrote. Can someone let me know how to go next?

system("cd /home/user/Source/pxe/")

I want the terminal to point to the folder pxewhen I run the ruby ​​script. Is the code correct? If not, can you tell me which is the right way to invoke a command cdfrom ruby ​​script?

+4
source share
2 answers

Do you want to change the current directory for the script? Use Dir.chdir .

Dir.chdir('/home/user/Source/pxe')
+6
source

You can also use the method . FileUtils#cd

dir.If , .

( windows-7): ​​

require 'fileutils'

Dir.pwd # => "C:/Program Files/Notepad++"
FileUtils.cd("C:\\Users\\rakshiar\\Downloads")
Dir.pwd # => "C:/Users/rakshiar/Downloads"
+1

All Articles