vendredi 8 mars 2019

How to obtain basename in ruby from the given file path in unix or windows format?

I need to parse a basename in ruby a from file path which I get as input. Unix format works fine.

File.basename("/tmp/text.txt")

return "text.txt".
However, when I get input in windows format:

File.basename("C:\Users\john\note.txt")

"C:Usersjohn\note.txt" is the output.

Is there some nice solution in ruby/rails?

Aucun commentaire:

Enregistrer un commentaire