I want to write a application that works in windows and linux. but I have a path problem because windows use \"\\\" and Linux use \"/\" .how can I solve this problem. thanks
In Ruby, there is no difference between the paths in Linux or Windows. The path should be using /
regardless of environment. So, for using any path in Windows, replace all \
with /
. File#join
will work for both Windows and Linux. For example, in Windows:
Dir.pwd
=> "C/Documents and Settings/Users/prince"
File.open(Dir.pwd + "/Desktop/file.txt", "r")
=> #
File.open(File.join(Dir.pwd, "Desktop", "file.txt"), "r")
=> #
File.join(Dir.pwd, "Desktop", "file.txt")
=> "C/Documents and Settings/Users/prince/Desktop/file.txt"