Forum: Ruby-core [ruby-trunk - Bug #5994][Open] Dir.glob without wildcards returns pattern, not filename

Posted by Dave B (Guest)
on 2012-02-10 04:53
(Received via mailing list)
Issue #5994 has been reported by Dave B.

----------------------------------------
Bug #5994: Dir.glob without wildcards returns pattern, not filename
https://bugs.ruby-lang.org/issues/5994

Author: Dave B
Status: Open
Priority: Low
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]



This is Windows specific, I guess, as filename case doesn't matter 
there.
Ruby version is not specific to 1.9.3p0 (ruby 1.8.7p334 gives the same).
The script below produces results that seem inconsistent.
Using special characters (wildcards) in the glob pattern returns the
actual filename on disk but a plain pattern (no wildcards) returns the
pattern itself.  This means I have to use another method for producing
a file with the same name or else override the users case-style
preference (which is not my intention).

daz

#======================
puts 'ruby %sp%d (%s) [%s]' % [RUBY_VERSION, RUBY_PATCHLEVEL, 
RUBY_RELEASE_DATE, RUBY_PLATFORM]
# ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

Dir.chdir ENV['TEMP']
TMPDIR = Time.now.strftime('%Y%m%d_%H%M%S_delete')
Dir.mkdir(TMPDIR)
Dir.chdir(TMPDIR)

TMPFN  = 'Foo'
File.open(TMPFN, 'w') {}

#----------------------------------------------
p Dir.glob('*')   #=> ["Foo"]  ok
p Dir.glob('f?O') #=> ["Foo"]  ok

# But a glob without special characters returns
#  the glob pattern instead of the filename
p Dir.glob('foO') #=> ["foO"]  not wanted
p Dir['foO']      #=> ["foO"]  same as above
p Dir.glob('foO', File::FNM_CASEFOLD)
                # casefold ignored, as docs say
#----------------------------------------------

File.delete(TMPFN)
Dir.delete(File.join('..', TMPDIR))


#+++++
# Same incorrect results from:
#   ruby 1.8.7p334 (2011-02-18) [i386-mingw32]
Posted by Dave B (Guest)
on 2012-02-10 05:24
(Received via mailing list)
Issue #5994 has been updated by Dave B.



This *nix behaviour would be fine, for me.

# ruby 1.8.7p302 (2010-08-16) [i486-linux]
#-----------------------------------------------------
p Dir.glob('*')                        #=> ["Foo"]  ok
p Dir.glob('f?O')                      #=> []       ok
p Dir.glob('foO')                      #=> []       ok
p Dir.glob('foO', File::FNM_CASEFOLD)  #=> ["Foo"]  ok
#-----------------------------------------------------

( Couldn't find an ENV['TEMP'] .. used ENV['HOME'] )

daz

----------------------------------------
Bug #5994: Dir.glob without wildcards returns pattern, not filename
https://bugs.ruby-lang.org/issues/5994

Author: Dave B
Status: Open
Priority: Low
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]



This is Windows specific, I guess, as filename case doesn't matter 
there.
Ruby version is not specific to 1.9.3p0 (ruby 1.8.7p334 gives the same).
The script below produces results that seem inconsistent.
Using special characters (wildcards) in the glob pattern returns the
actual filename on disk but a plain pattern (no wildcards) returns the
pattern itself.  This means I have to use another method for producing
a file with the same name or else override the users case-style
preference (which is not my intention).

daz

#======================
puts 'ruby %sp%d (%s) [%s]' % [RUBY_VERSION, RUBY_PATCHLEVEL, 
RUBY_RELEASE_DATE, RUBY_PLATFORM]
# ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

Dir.chdir ENV['TEMP']
TMPDIR = Time.now.strftime('%Y%m%d_%H%M%S_delete')
Dir.mkdir(TMPDIR)
Dir.chdir(TMPDIR)

TMPFN  = 'Foo'
File.open(TMPFN, 'w') {}

#----------------------------------------------
p Dir.glob('*')   #=> ["Foo"]  ok
p Dir.glob('f?O') #=> ["Foo"]  ok

# But a glob without special characters returns
#  the glob pattern instead of the filename
p Dir.glob('foO') #=> ["foO"]  not wanted
p Dir['foO']      #=> ["foO"]  same as above
p Dir.glob('foO', File::FNM_CASEFOLD)
                # casefold ignored, as docs say
#----------------------------------------------

File.delete(TMPFN)
Dir.delete(File.join('..', TMPDIR))


#+++++
# Same incorrect results from:
#   ruby 1.8.7p334 (2011-02-18) [i386-mingw32]
Posted by Nobuyoshi Nakada (nobu)
on 2012-02-10 07:33
(Received via mailing list)
Issue #5994 has been updated by Nobuyoshi Nakada.

Category set to core
Status changed from Open to Feedback
Target version set to 2.0.0

=begin
Dave B wrote:
  p Dir.glob('foO') #=> ["foO"]  not wanted

What do you want, an empty array same as case-sensitive systems?
=end

----------------------------------------
Bug #5994: Dir.glob without wildcards returns pattern, not filename
https://bugs.ruby-lang.org/issues/5994

Author: Dave B
Status: Feedback
Priority: Low
Assignee:
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]


This is Windows specific, I guess, as filename case doesn't matter 
there.
Ruby version is not specific to 1.9.3p0 (ruby 1.8.7p334 gives the same).
The script below produces results that seem inconsistent.
Using special characters (wildcards) in the glob pattern returns the
actual filename on disk but a plain pattern (no wildcards) returns the
pattern itself.  This means I have to use another method for producing
a file with the same name or else override the users case-style
preference (which is not my intention).

daz

#======================
puts 'ruby %sp%d (%s) [%s]' % [RUBY_VERSION, RUBY_PATCHLEVEL, 
RUBY_RELEASE_DATE, RUBY_PLATFORM]
# ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

Dir.chdir ENV['TEMP']
TMPDIR = Time.now.strftime('%Y%m%d_%H%M%S_delete')
Dir.mkdir(TMPDIR)
Dir.chdir(TMPDIR)

TMPFN  = 'Foo'
File.open(TMPFN, 'w') {}

#----------------------------------------------
p Dir.glob('*')   #=> ["Foo"]  ok
p Dir.glob('f?O') #=> ["Foo"]  ok

# But a glob without special characters returns
#  the glob pattern instead of the filename
p Dir.glob('foO') #=> ["foO"]  not wanted
p Dir['foO']      #=> ["foO"]  same as above
p Dir.glob('foO', File::FNM_CASEFOLD)
                # casefold ignored, as docs say
#----------------------------------------------

File.delete(TMPFN)
Dir.delete(File.join('..', TMPDIR))


#+++++
# Same incorrect results from:
#   ruby 1.8.7p334 (2011-02-18) [i386-mingw32]
Posted by Dave B (Guest)
on 2012-02-10 08:27
(Received via mailing list)
Issue #5994 has been updated by Dave B.


Hi Nobu,

I expected:

p Dir.glob('foO') #=> ["Foo"]

The current behaviour would be difficult to justify.
The doc string says ...
"Returns the filenames found by expanding <i>pattern</i> ..."

There is no filename "foO"; it exists only as a glob pattern.

Instead of answering the question "Are there files which match this
pattern", it has answered an artificial question "What glob pattern
did I use to search for files"; I already knew the answer to that. ;)

Background:
I'm doing a Windows System Restore from Linux and the registry databases
are not things I want to make subtle changes to.

WINDIR   = '/media/XYSRES/WINDOWS'
CONFIG   = File.join( WINDIR, 'system32', 'config' )
Dir.chdir CONFIG

hives = %w{ system software sam security default }

# Can't do this ...
p HIVES_NO = hives.map {|hvn| Dir[hvn][0] }
#=> ["system", "software", "sam", "security", "default"]

# Have to do this, instead ...
p HIVES_OK = Dir['*'].delete_if {|fn| !hives.include?(fn.downcase)}
#=> ["default", "SAM", "SECURITY", "software", "system"]


Cheers,

daz

----------------------------------------
Bug #5994: Dir.glob without wildcards returns pattern, not filename
https://bugs.ruby-lang.org/issues/5994

Author: Dave B
Status: Feedback
Priority: Low
Assignee:
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]


This is Windows specific, I guess, as filename case doesn't matter 
there.
Ruby version is not specific to 1.9.3p0 (ruby 1.8.7p334 gives the same).
The script below produces results that seem inconsistent.
Using special characters (wildcards) in the glob pattern returns the
actual filename on disk but a plain pattern (no wildcards) returns the
pattern itself.  This means I have to use another method for producing
a file with the same name or else override the users case-style
preference (which is not my intention).

daz

#======================
puts 'ruby %sp%d (%s) [%s]' % [RUBY_VERSION, RUBY_PATCHLEVEL, 
RUBY_RELEASE_DATE, RUBY_PLATFORM]
# ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

Dir.chdir ENV['TEMP']
TMPDIR = Time.now.strftime('%Y%m%d_%H%M%S_delete')
Dir.mkdir(TMPDIR)
Dir.chdir(TMPDIR)

TMPFN  = 'Foo'
File.open(TMPFN, 'w') {}

#----------------------------------------------
p Dir.glob('*')   #=> ["Foo"]  ok
p Dir.glob('f?O') #=> ["Foo"]  ok

# But a glob without special characters returns
#  the glob pattern instead of the filename
p Dir.glob('foO') #=> ["foO"]  not wanted
p Dir['foO']      #=> ["foO"]  same as above
p Dir.glob('foO', File::FNM_CASEFOLD)
                # casefold ignored, as docs say
#----------------------------------------------

File.delete(TMPFN)
Dir.delete(File.join('..', TMPDIR))


#+++++
# Same incorrect results from:
#   ruby 1.8.7p334 (2011-02-18) [i386-mingw32]
Posted by ko1 (Koichi Sasada) (Guest)
on 2012-10-27 02:27
(Received via mailing list)
Issue #5994 has been updated by ko1 (Koichi Sasada).

Status changed from Feedback to Assigned
Assignee set to nobu (Nobuyoshi Nakada)

nobu, could you reply to it?

----------------------------------------
Bug #5994: Dir.glob without wildcards returns pattern, not filename
https://bugs.ruby-lang.org/issues/5994#change-31729

Author: daz (Dave B)
Status: Assigned
Priority: Low
Assignee: nobu (Nobuyoshi Nakada)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]


This is Windows specific, I guess, as filename case doesn't matter 
there.
Ruby version is not specific to 1.9.3p0 (ruby 1.8.7p334 gives the same).
The script below produces results that seem inconsistent.
Using special characters (wildcards) in the glob pattern returns the
actual filename on disk but a plain pattern (no wildcards) returns the
pattern itself.  This means I have to use another method for producing
a file with the same name or else override the users case-style
preference (which is not my intention).

daz

#======================
puts 'ruby %sp%d (%s) [%s]' % [RUBY_VERSION, RUBY_PATCHLEVEL, 
RUBY_RELEASE_DATE, RUBY_PLATFORM]
# ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

Dir.chdir ENV['TEMP']
TMPDIR = Time.now.strftime('%Y%m%d_%H%M%S_delete')
Dir.mkdir(TMPDIR)
Dir.chdir(TMPDIR)

TMPFN  = 'Foo'
File.open(TMPFN, 'w') {}

#----------------------------------------------
p Dir.glob('*')   #=> ["Foo"]  ok
p Dir.glob('f?O') #=> ["Foo"]  ok

# But a glob without special characters returns
#  the glob pattern instead of the filename
p Dir.glob('foO') #=> ["foO"]  not wanted
p Dir['foO']      #=> ["foO"]  same as above
p Dir.glob('foO', File::FNM_CASEFOLD)
                # casefold ignored, as docs say
#----------------------------------------------

File.delete(TMPFN)
Dir.delete(File.join('..', TMPDIR))


#+++++
# Same incorrect results from:
#   ruby 1.8.7p334 (2011-02-18) [i386-mingw32]
Posted by ko1 (Koichi Sasada) (Guest)
on 2013-02-24 13:26
(Received via mailing list)
Issue #5994 has been updated by ko1 (Koichi Sasada).

Target version changed from 2.0.0 to 2.1.0

ping -> nobu
----------------------------------------
Feature #5994: Dir.glob without wildcards returns pattern, not filename
https://bugs.ruby-lang.org/issues/5994#change-36914

Author: daz (Dave B)
Status: Assigned
Priority: Low
Assignee: nobu (Nobuyoshi Nakada)
Category: core
Target version: 2.1.0


This is Windows specific, I guess, as filename case doesn't matter 
there.
Ruby version is not specific to 1.9.3p0 (ruby 1.8.7p334 gives the same).
The script below produces results that seem inconsistent.
Using special characters (wildcards) in the glob pattern returns the
actual filename on disk but a plain pattern (no wildcards) returns the
pattern itself.  This means I have to use another method for producing
a file with the same name or else override the users case-style
preference (which is not my intention).

daz

#======================
puts 'ruby %sp%d (%s) [%s]' % [RUBY_VERSION, RUBY_PATCHLEVEL, 
RUBY_RELEASE_DATE, RUBY_PLATFORM]
# ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

Dir.chdir ENV['TEMP']
TMPDIR = Time.now.strftime('%Y%m%d_%H%M%S_delete')
Dir.mkdir(TMPDIR)
Dir.chdir(TMPDIR)

TMPFN  = 'Foo'
File.open(TMPFN, 'w') {}

#----------------------------------------------
p Dir.glob('*')   #=> ["Foo"]  ok
p Dir.glob('f?O') #=> ["Foo"]  ok

# But a glob without special characters returns
#  the glob pattern instead of the filename
p Dir.glob('foO') #=> ["foO"]  not wanted
p Dir['foO']      #=> ["foO"]  same as above
p Dir.glob('foO', File::FNM_CASEFOLD)
                # casefold ignored, as docs say
#----------------------------------------------

File.delete(TMPFN)
Dir.delete(File.join('..', TMPDIR))


#+++++
# Same incorrect results from:
#   ruby 1.8.7p334 (2011-02-18) [i386-mingw32]
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.