I often use long paths in my scripts and since i'm on windows i have to convert these long paths to nix style with slashes in stead of backslashes. Nothing difficult but annoying if thereafter you copy that path to go to that folder since in explorer you have to do the opposite again.
So i made a function that does the conversion, now i can use windowspaths that i can copy around and keep Ruby sattisfied.
Question: is there a more elegant solution here ? I don't like the second gsub to handle the double \ at he beginning and also would like to handle a \ at the end (currently not possible). The function should be able to handle network unc's (\..) and local drivepaths (c:..)
class String
def path
self.gsub('\\','/').gsub(/^\//,'//')
end
end
path = '\\server\share\folder'.path
Dir.glob(path+'**/*') do |file|
puts file
end
#=>
#//server/share/folder/file1.txt
#//server/share/folder/file2.txt