[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

FileTest::exists? Not Finding Windows Files with Spaces in Name

John from Arran

5/3/2005 11:35:00 AM

Hello,

Please help with the following:

Ruby's FileTest::exists? is not finding Windows files with spaces in
their name. I could use a work-around like grep'ping the result of 'ls
<filename>' (I use Cygwin), but I'm thinking there must be a way to
make FileTest do the work.

Best regards,

Dennis
7 Answers

djberg96

5/3/2005 12:47:00 PM

0

Dennis Mendelson wrote:
> Hello,
>
> Please help with the following:
>
> Ruby's FileTest::exists? is not finding Windows files with spaces in
> their name. I could use a work-around like grep'ping the result of
'ls
> <filename>' (I use Cygwin), but I'm thinking there must be a way to
> make FileTest do the work.
>
> Best regards,
>
> Dennis

If this is an issue, it must be particular to cygwin:

irb(main):002:0> File.exists?("C:\\Program Files")
=> true

Do you have some sample code you could show us?

Regards,

Dan

John from Arran

5/3/2005 12:53:00 PM

0

Should have mentioned that I have tried using double-quotes in the
following ways:

"C:\Documents and Settings\test.txt"; and

C:\"Documents and Settings"\test.txt, both of which Windows
recognises.

Dennis

On Tue, 03 May 2005 12:35:21 +0100, Dennis Mendelson <nobody@home.org>
wrote:

>Hello,
>
>Please help with the following:
>
>Ruby's FileTest::exists? is not finding Windows files with spaces in
>their name. I could use a work-around like grep'ping the result of 'ls
><filename>' (I use Cygwin), but I'm thinking there must be a way to
>make FileTest do the work.
>
>Best regards,
>
>Dennis

Dave Burt

5/3/2005 1:25:00 PM

0

"Dennis Mendelson" <nobody@home.org> asserted:
> Should have mentioned that I have tried using double-quotes in the
> following ways:
>
> "C:\Documents and Settings\test.txt"; and
>
> C:\"Documents and Settings"\test.txt, both of which Windows
> recognises.

Have you tried with no quotes within the String, like Daniel's example?

FWIW This works for me under WinXP/Cygwin:

Dave@telperion ~
$ ruby -ve "puts File.exists?('My Documents')"
ruby 1.8.2 (2004-12-25) [i386-mswin32]
true

Cheers,
Dave


Robert Klemme

5/3/2005 1:41:00 PM

0

Dennis Mendelson wrote:
> Should have mentioned that I have tried using double-quotes in the
> following ways:
>
> "C:\Documents and Settings\test.txt"; and

>> puts "C:\Documents and Settings\test.txt"
C:Documents and Settings est.txt
=> nil

Notice something? You need double backslashes in double quotes.
Alternatively use single quotes

>> puts 'C:\Documents and Settings\test.txt'
C:\Documents and Settings\test.txt
=> nil

> C:\"Documents and Settings"\test.txt, both of which Windows
> recognises.

This is incorrect Ruby syntax:

>> C:\"Documents and Settings"\test.txt
SyntaxError: compile error
(irb):2: syntax error
C:\"Documents and Settings"\test.txt
^
(irb):2: syntax error
C:\"Documents and Settings"\test.txt
^
from (irb):2

Note, ruby != bash

Kind regards

robert

Ara.T.Howard

5/3/2005 2:52:00 PM

0

John from Arran

5/3/2005 5:54:00 PM

0

Thanks to all posters - I have this sorted out now.

Dennis

On Tue, 03 May 2005 12:35:21 +0100, Dennis Mendelson <nobody@home.org>
wrote:

>Hello,
>
>Please help with the following:
>
>Ruby's FileTest::exists? is not finding Windows files with spaces in
>their name. I could use a work-around like grep'ping the result of 'ls
><filename>' (I use Cygwin), but I'm thinking there must be a way to
>make FileTest do the work.
>
>Best regards,
>
>Dennis

David Corbin

5/7/2005 9:23:00 AM

0

On Tuesday 03 May 2005 09:44 am, Robert Klemme wrote:
> Dennis Mendelson wrote:
> > Should have mentioned that I have tried using double-quotes in the
> > following ways:
> >
> > "C:\Documents and Settings\test.txt"; and
> >
> >> puts "C:\Documents and Settings\test.txt"
>
> C:Documents and Settings est.txt
> => nil
>
> Notice something? You need double backslashes in double quotes.
> Alternatively use single quotes
>

Or just you forward slashes, the Ruby standard.