# Windows directories not recognized by ruby?

**URL:** <https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491>\
**Category:** Ruby\
**Created:** [April 7, 2011, 4:03pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491 "2011-04-07T16:03:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 7, 2011, 4:03pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491/1 "2011-04-07T16:03:00Z")

</div>

What’s wrong with this code?

C:\>mkdir test\_ruby

C:\>irb  
irb(main):001:0\> File.directory? “c:”  
=\> true  
irb(main):002:0\> File.directory? “c:\test\_ruby”  
=\> false  
irb(main):003:0\>

Thanks for any ideas in advance,

-Kalman

---

<div class="post-metadata">

**Author:** ![kalman\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kalman\_h](https://www.ruby-forum.com/u/kalman_h)\
**Post date:** [April 7, 2011, 4:24pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491/2 "2011-04-07T16:24:43Z")

</div>

On Thu, Apr 7, 2011 at 16:03, Kalman H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):002:0\> File.directory? “c:\test\_ruby”

You may want to escape your reverse solidus (backslash), or, better  
yet, use a solidus (slash, virgule) instead.

---

<div class="post-metadata">

**Author:** ![kalman\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kalman\_h](https://www.ruby-forum.com/u/kalman_h)\
**Post date:** [April 7, 2011, 4:31pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491/3 "2011-04-07T16:31:31Z")

</div>

On Thu, Apr 7, 2011 at 4:03 PM, Kalman H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

The \ is an escape character, so you are actually checking for “c:  
est\_ruby” (\t is is the escape sequence for a tab character)

Either try

File.directory? “c:\test\_ruby”

or

File.directory? “c:/test\_ruby”

Windows NT _at least_ since Vista, but probably XP already, and maybe  
even the original NT 3.51, support the forward slash in the command  
line.

–  
Phillip G.

Though the folk I have met,  
(Ah, how soon!) they forget  
When I’ve moved on to some other place,  
There may be one or two,  
When I’ve played and passed through,  
Who’ll remember my song or my face.

---

<div class="post-metadata">

**Author:** ![kalman\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kalman\_h](https://www.ruby-forum.com/u/kalman_h)\
**Post date:** [April 7, 2011, 4:33pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491/4 "2011-04-07T16:33:23Z")

</div>

On Apr 7, 3:03pm, “Kalman H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for any ideas in advance,
> 
> -Kalman
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

It’s the way Ruby handles your strings. You are using double quotes,  
so you need to escape the backslash. If you use single quotes, you can  
use the single backslash. Look at the following:

irb(main):001:0\> File.directory? “C:”  
=\> true  
irb(main):002:0\> File.directory? “C:\Users”  
=\> false  
irb(main):003:0\> File.directory? “C:\Users”  
=\> true  
irb(main):004:0\> File.directory? ‘C:\Users’  
=\> true

HTH

Paul

---

<div class="post-metadata">

**Author:** ![kalman\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kalman\_h](https://www.ruby-forum.com/u/kalman_h)\
**Post date:** [April 7, 2011, 8:16pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491/5 "2011-04-07T20:16:23Z")

</div>

On Apr 7, 6:03pm, “Kalman H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for any ideas in advance,
> 
> -Kalman
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

You should use File.directory? File.join(%w[c: test\_ruby])

---

<div class="post-metadata">

**Author:** ![kalman\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kalman\_h](https://www.ruby-forum.com/u/kalman_h)\
**Post date:** [April 7, 2011, 5:46pm UTC](https://www.ruby-forum.com/t/windows-directories-not-recognized-by-ruby/205491/6 "2011-04-07T17:46:26Z")

</div>

> Windows NT _at least_ since Vista, but probably XP already, and maybe  
> even the original NT 3.51, support the forward slash in the command  
> line.

ForwardSlash works since MSDOS !

From wikipedia “Backslash” :

“The Windows API can accept either the backslash or slash to separate  
directory and file components of a path, but the Microsoft convention is  
to use a backslash, and APIs that return paths put backslash in.[7]  
MS-DOS 2.0 copied the hierarchical file system from Unix and thus used  
the forward slash, but (possibly on the insistence of IBM) added the  
backslash to allow paths to be typed into the command shell while  
retaining compatibility with MS-DOS 1.0 and CP/M where the slash was the  
command-line option indicator (i.e. as in typing “dir/w” to give the  
“wide” option to the “dir” command).[8] Although the command shell was  
the only part of MS-DOS that required this, the use of backslash in  
filenames was propagated to most other parts of the user interface”
