Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dir[] and Windows Network Addresses

71 views
Skip to first unread message

Brian Takita

unread,
Jun 23, 2005, 5:08:27 PM6/23/05
to
Hello,

Is is possible to get the contents of a Windows network directory using
Dir?

I would think it would be something like
Dir['\\\\Computer\\Dir\\*']
but nothing shows up.

Is there a way to access the a Windows network directory without having
to call
exec 'dir \\\\Computer\\Dir'
and parsing the output?

Thank you,
Brian Takita

Berger, Daniel

unread,
Jun 23, 2005, 5:36:50 PM6/23/05
to

Watch the single versus double quotes. However, that's not the problem
anway.

Specifying the root makes it fail:

irb(main):019:0> Dir["*.*"]
=> ["AUTOEXEC.BAT", "boot.ini"] # Much snippage

irb(main):016:0> Dir["C:\\*.*"]
=> []

However, Dir.entries should do the trick in the meantime:

irb(main):017:0> Dir.entries("\\\\vadevweb\\public")
=> [".", "..", "Builds", "Devtools", "Projects", "vss"]

Looks like a bug in Dir.glob to me.

Regards,

Dan

PS - Find.find seems to handle UNC paths alright, too.


Charles Mills

unread,
Jun 23, 2005, 5:54:15 PM6/23/05
to

Yeah, this is funny:

irb(main):001:0> Dir['C:\\*.*']
=> []
irb(main):002:0> Dir['C:/*.*']
=> ["C:/AUTOEXEC.BAT", "C:/BOOT.INI", "C:/BOOTSECT.DOS",
"C:/COMLOG.txt", "C:/CONFIG.SYS", "C:/DELL.SDR", "C:/hiberfil.sys",
"C:/IO.SYS", "C:/MSDOS.SYS", "C:/NTDETECT.COM", "C:/pagefile.sys",
"C:/volumeid.zbx"]

That was using the irb from the 1-click installer, same thing happens
using Ruby on Cygwin.

-Charlie

nobu....@softhome.net

unread,
Jun 23, 2005, 7:40:57 PM6/23/05
to
Hi,

At Fri, 24 Jun 2005 06:36:50 +0900,
Berger, Daniel wrote in [ruby-talk:146310]:


> However, Dir.entries should do the trick in the meantime:
>
> irb(main):017:0> Dir.entries("\\\\vadevweb\\public")
> => [".", "..", "Builds", "Devtools", "Projects", "vss"]
>
> Looks like a bug in Dir.glob to me.

Not a bug. Backslash is a metacharacter, so you have to use
forward slashes instead.

Dir.entries("//vadevweb/public")

--
Nobu Nakada


Brian Takita

unread,
Jun 30, 2005, 6:28:21 PM6/30/05
to
That works, thank you.

0 new messages