Ruby File Path Separators

File path separators on Unix systems and Windows are different. On Unix, a forward slash / is used and on Windows a backslash \ is used.

However, when writing Ruby code you don’t need to worry about this; Just use the forward slash / character and it will be cross-platform for you.

An even better option is to use File.join to join a paths together. The correct file path separator for the particular platform will be used. See File.join

When using the File.join method for absolute paths, the first argument to the join method must be an empty string.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Facebook Twitter Email

Leave a Reply