Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Windows directories not recognized by ruby?

Reply
Thread Tools

Windows directories not recognized by ruby?

 
 
Kalman H.
Guest
Posts: n/a
 
      04-07-2011
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Nikolai Weibull
Guest
Posts: n/a
 
      04-07-2011
On Thu, Apr 7, 2011 at 16:03, Kalman H. <> 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.

 
Reply With Quote
 
 
 
 
paul h
Guest
Posts: n/a
 
      04-07-2011
On Apr 7, 3:03*pm, "Kalman H." <kalm...@gmail.com> wrote:
> 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
>
> --
> 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
 
Reply With Quote
 
Phillip Gawlowski
Guest
Posts: n/a
 
      04-07-2011
On Thu, Apr 7, 2011 at 4:03 PM, Kalman H. <> wrote:
> 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>
>


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 Gawlowski

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.

 
Reply With Quote
 
Regis d'Aubarede
Guest
Posts: n/a
 
      04-07-2011
> 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"

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
koulikoff
Guest
Posts: n/a
 
      04-07-2011
On Apr 7, 6:03*pm, "Kalman H." <kalm...@gmail.com> wrote:
> 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
>
> --
> Posted viahttp://www.ruby-forum.com/.


You should use File.directory? File.join(%w[c: test_ruby])
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Directories and Physical directories Paul M Fin MCAD 4 06-27-2008 07:50 PM
virtual directories/physical directories in IIS Paul F ASP .Net 4 06-25-2008 04:04 PM
Multiple bin-directories with virtual directories? =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?= ASP .Net 0 11-09-2004 05:49 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM
Using virtual directories for common directories (scripts, images, styles, etc.) Jeffry van de Vuurst ASP .Net 2 07-30-2003 07:00 PM



Advertisments