# OS independent way to read/write paths?

**URL:** <https://rubytalk.org/t/os-independent-way-to-read-write-paths/20347>\
**Category:** ruby-talk\
**Created:** [23 August 2005 12:10 UTC](https://rubytalk.org/t/os-independent-way-to-read-write-paths/20347 "2005-08-23T12:10:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Wells](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@John\_Wells](https://rubytalk.org/u/John_Wells)\
**Post date:** [23 August 2005 12:10 UTC](https://rubytalk.org/t/os-independent-way-to-read-write-paths/20347/1 "2005-08-23T12:10:41Z")

</div>

Guys,

I'm running into some problems running scripts on Windows that do file  
path mangling. Problem is that it appears Ruby converts all windows paths  
to forward slashes as opposed to back slashes...fine by me, but I need to  
write them out on occasion for consumption by other Windows programs or  
batch files, and then I have a problem.

I know this would be a relatively simple thing to handle on my own, but  
wanted to know if, by my newness to Ruby, I'm missing a wheel that's  
already been invented. What's the idiomatic way of handling this sort of  
problem?

Thanks!  
John

---

<div class="post-metadata">

**Author:** ![Austin\_Ziegler5](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/austin_ziegler5/32/1985_2.png) [@Austin\_Ziegler5](https://rubytalk.org/u/Austin_Ziegler5)\
**Post date:** [23 August 2005 13:56 UTC](https://rubytalk.org/t/os-independent-way-to-read-write-paths/20347/2 "2005-08-23T13:56:04Z")

</div>

winpath = rubypath.gsub(%r{/}, "\\")

😉

-austin

> **···**
>
> On 8/23/05, John Wells \<lists@sourceillustrated.com\> wrote:
> 
> > I'm running into some problems running scripts on Windows that do file  
> > path mangling. Problem is that it appears Ruby converts all windows paths  
> > to forward slashes as opposed to back slashes...fine by me, but I need to  
> > write them out on occasion for consumption by other Windows programs or  
> > batch files, and then I have a problem.
> > 
> > I know this would be a relatively simple thing to handle on my own, but  
> > wanted to know if, by my newness to Ruby, I'm missing a wheel that's  
> > already been invented. What's the idiomatic way of handling this sort of  
> > problem?
> 
> --  
> Austin Ziegler \* halostatue@gmail.com  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\* Alternate: austin@halostatue.ca
