Normalize Windows Path Names

R

rtilley

Is there a way to normalize pathnames? On Windows, many system calls
return a windows path that contains back slashes like this:

C:\windows\system32

I'd prefer to have forward slashes since they are easier to work with
like this:

C:/windows/system32

Windows will accept either slash. What is the best way for Ruby to
convert to normal slashes?

Thank you,
Brad
 
D

Daniel Berger

rtilley said:
Is there a way to normalize pathnames? On Windows, many system calls
return a windows path that contains back slashes like this:

C:\windows\system32

I'd prefer to have forward slashes since they are easier to work with
like this:

C:/windows/system32

Windows will accept either slash. What is the best way for Ruby to
convert to normal slashes?

See String#tr and String#tr!

"C:\\foo\\bar".tr("\\", '/') # C:/foo/bar

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top