# Case of drive letter

**URL:** <https://www.ruby-forum.com/t/case-of-drive-letter/164960>\
**Category:** IronRuby\
**Created:** [April 7, 2009, 8:50pm UTC](https://www.ruby-forum.com/t/case-of-drive-letter/164960 "2009-04-07T20:50:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [April 7, 2009, 8:50pm UTC](https://www.ruby-forum.com/t/case-of-drive-letter/164960/1 "2009-04-07T20:50:53Z")

</div>

Using MRI on Windows, Dir.pwd can use either lower-case or upper-case  
for the drive letter (“C:/” or “c:/”) depending on the Command Prompt it  
is run from. However, **FILE** always uses lower-case drive letter. This  
can cause problems when comparing Dir.pwd and **FILE**. For eg,  
Pathname#relative\_path\_from[http://ruby-doc.org/core/classes/Pathname.html#M001745](http://ruby-doc.org/core/classes/Pathname.html#M001745)  
raises an ArgumentError if the arguments use different cases for the  
drive letter.

C:\Users\sborde\> cat c:\bugs\rb1.rb  
require ‘pathname’  
Pathname.new(Dir.pwd).relative\_path\_from(Pathname.new( **FILE** ))

C:\Users\sborde\> c:\Ruby\bin\ruby.exe c:\bugs\rb1.rb  
c:/Ruby/lib/ruby/1.8/pathname.rb:709:in `relative\_path\_from’: different  
prefix:  
“C:/” and “c:/bugs/rb1.rb” (ArgumentError)  
from c:/bugs/rb1.rb:2

I did not find any good documentation on which case is used by Command  
Prompt, but [[MERGE] win32 important fix: convert drive letter to uppercase not lowercase](https://lists.ubuntu.com/archives/bazaar/2006q2/013921.html)  
refers to the issue. I can create Command Prompts with either case by  
creating a shortcut on the desktop, and specifying a “Start in” folder  
property for the shortcut. Command Prompt will use the case specified  
for the “Start in” folder.

Does anyone have experience dealing with this issue? What is the  
recommended solution? I would rather not check the case of the drive  
letter manually. I looked for APIs which would convert the drive letter  
to lower-case, but could not find anything.

Thanks,  
Shri

---

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [April 21, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/case-of-drive-letter/164960/2 "2009-04-21T20:00:35Z")

</div>

(Responding late … hopefully this is still useful)

> > > **FILE** always uses lower-case drive letter

**FILE** is just the value you gave to require/load. **FILE** and  
$PROGRAM\_NAME only get munged with when running ruby.exe, but it doesn’t  
touch casing, only changes all directory separators to ‘/’.

# c:\dev\foo.rb

module Foo  
def self.file  
**FILE**  
end  
end  
puts Foo.file

c:\dev\ironruby\>irb  
irb(main):001:0\> load ‘C:\dev\foo.rb’  
“C:\dev\foo.rb”  
=\> true

c:\dev\ironruby\>irb  
irb(main):001:0\> load ‘c:\dev\foo.rb’  
“c:\dev\foo.rb”  
=\> true

c:\dev\ironruby\>ruby c:\dev\foo.rb  
c:/dev/foo.rb

c:\dev\ironruby\>ruby C:\dev\foo.rb  
C:/dev/foo.rb

My recent **FILE** changes made IronRuby work identically to MRI, but  
that only changes the path separator, does nothing with casing. IronRuby  
behaves the same as this.

~js

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Shri B.  
Sent: Tuesday, April 07, 2009 11:36 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Case of drive letter

Using MRI on Windows, Dir.pwd can use either lower-case or upper-case  
for the drive letter (“C:/” or “c:/”) depending on the Command Prompt it  
is run from. However, **FILE** always uses lower-case drive letter. This  
can cause problems when comparing Dir.pwd and **FILE**. For eg,  
Pathname#relative\_path\_from[http://ruby-doc.org/core/classes/Pathname.html#M001745](http://ruby-doc.org/core/classes/Pathname.html#M001745)  
raises an ArgumentError if the arguments use different cases for the  
drive letter.

C:\Users\sborde\> cat c:\bugs\rb1.rb  
require ‘pathname’  
Pathname.new(Dir.pwd).relative\_path\_from(Pathname.new( **FILE** ))

C:\Users\sborde\> c:\Ruby\bin\ruby.exe c:\bugs\rb1.rb  
c:/Ruby/lib/ruby/1.8/pathname.rb:709:in `relative\_path\_from’: different  
prefix:  
“C:/” and “c:/bugs/rb1.rb” (ArgumentError)  
from c:/bugs/rb1.rb:2

I did not find any good documentation on which case is used by Command  
Prompt, but [[MERGE] win32 important fix: convert drive letter to uppercase not lowercase](https://lists.ubuntu.com/archives/bazaar/2006q2/013921.html)  
refers to the issue. I can create Command Prompts with either case by  
creating a shortcut on the desktop, and specifying a “Start in” folder  
property for the shortcut. Command Prompt will use the case specified  
for the “Start in” folder.

Does anyone have experience dealing with this issue? What is the  
recommended solution? I would rather not check the case of the drive  
letter manually. I looked for APIs which would convert the drive letter  
to lower-case, but could not find anything.

Thanks,  
Shri

---

<div class="post-metadata">

**Author:** ![Shri\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Shri\_B](https://www.ruby-forum.com/u/Shri_B)\
**Post date:** [April 21, 2009, 8:27pm UTC](https://www.ruby-forum.com/t/case-of-drive-letter/164960/3 "2009-04-21T20:27:01Z")

</div>

The case issue is tracked by the following MRI bug -  
[http://redmine.ruby-lang.org/issues/show/1266](http://redmine.ruby-lang.org/issues/show/1266). It will be fixed in some  
future version of MRI.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Jimmy  
Schementi  
Sent: Tuesday, April 21, 2009 10:59 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Case of drive letter

(Responding late … hopefully this is still useful)

> > > **FILE** always uses lower-case drive letter

**FILE** is just the value you gave to require/load. **FILE** and  
$PROGRAM\_NAME only get munged with when running ruby.exe, but it doesn’t  
touch casing, only changes all directory separators to ‘/’.

# c:\dev\foo.rb

module Foo  
def self.file  
**FILE**  
end  
end  
puts Foo.file

c:\dev\ironruby\>irb  
irb(main):001:0\> load ‘C:\dev\foo.rb’  
“C:\dev\foo.rb”  
=\> true

c:\dev\ironruby\>irb  
irb(main):001:0\> load ‘c:\dev\foo.rb’  
“c:\dev\foo.rb”  
=\> true

c:\dev\ironruby\>ruby c:\dev\foo.rb  
c:/dev/foo.rb

c:\dev\ironruby\>ruby C:\dev\foo.rb  
C:/dev/foo.rb

My recent **FILE** changes made IronRuby work identically to MRI, but  
that only changes the path separator, does nothing with casing. IronRuby  
behaves the same as this.

~js

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Shri B.  
Sent: Tuesday, April 07, 2009 11:36 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Case of drive letter

Using MRI on Windows, Dir.pwd can use either lower-case or upper-case  
for the drive letter (“C:/” or “c:/”) depending on the Command Prompt it  
is run from. However, **FILE** always uses lower-case drive letter. This  
can cause problems when comparing Dir.pwd and **FILE**. For eg,  
Pathname#relative\_path\_from[http://ruby-doc.org/core/classes/Pathname.html#M001745](http://ruby-doc.org/core/classes/Pathname.html#M001745)  
raises an ArgumentError if the arguments use different cases for the  
drive letter.

C:\Users\sborde\> cat c:\bugs\rb1.rb  
require ‘pathname’  
Pathname.new(Dir.pwd).relative\_path\_from(Pathname.new( **FILE** ))

C:\Users\sborde\> c:\Ruby\bin\ruby.exe c:\bugs\rb1.rb  
c:/Ruby/lib/ruby/1.8/pathname.rb:709:in `relative\_path\_from’: different  
prefix:  
“C:/” and “c:/bugs/rb1.rb” (ArgumentError)  
from c:/bugs/rb1.rb:2

I did not find any good documentation on which case is used by Command  
Prompt, but [[MERGE] win32 important fix: convert drive letter to uppercase not lowercase](https://lists.ubuntu.com/archives/bazaar/2006q2/013921.html)  
refers to the issue. I can create Command Prompts with either case by  
creating a shortcut on the desktop, and specifying a “Start in” folder  
property for the shortcut. Command Prompt will use the case specified  
for the “Start in” folder.

Does anyone have experience dealing with this issue? What is the  
recommended solution? I would rather not check the case of the drive  
letter manually. I looked for APIs which would convert the drive letter  
to lower-case, but could not find anything.

Thanks,  
Shri
