473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Filename case-insensitivity on OS X

Afternoon all,

MacOS X seems to have some heretical ideas about the value of case in
paths - it seems to believe that it doesn't exist, more or less, so "touch
foo FOO" touches just one file, you can't have both 'makefile' and
'Makefile' in the same directory,
"os.path.exists(some_valid_path.upper())" returns True even when
"os.path.split(some_valid_path.upper())[1] in
os.listdir(os.path.split(some_valid_path)[0])" returns False, etc
(although, of course, "ls *.txt" doesn't mention any of those .TXT files
lying around).

Just to prove it, here's what unix (specifically, linux) does:

twic@urchin:~$ uname
Linux
twic@urchin:~$ python
Python 2.3.5 (#2, Sep 4 2005, 22:01:42)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import os
filenames = os.listdir(".")
first = filenames[0]
first in filenames True first.upper() in filenames False os.path.exists(os.path.join(".", first)) True os.path.exists(os.path.join(".", first.upper())) False
And here's what OS X does:

Hooke:~ tom$ uname
Darwin
Hooke:~ tom$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information. import os
filenames = os.listdir(".")
first = filenames[0]
first in filenames True first.upper() in filenames False os.path.exists(os.path.join(".", first)) True os.path.exists(os.path.join(".", first.upper())) True


Sigh. Anyone got any bright ideas for working around this, specifically
for os.path.exists? I was hoping there was some os.path.actualpath, so i
could say:

def exists_dontignorecase(path):
return os.path.exists(path) and (path == os.path.actualpath(path))

Java has a java.io.File.getCanonicalPath method that does this, but i
can't find an equivalent in python - is there one?

I can emulate it like this:

def _canonicalise(s, l):
s = s.lower()
for t in l:
if s == t.lower():
return t
raise ValueError, ("could not canonicalise string", s)

def canonicalpath(path):
if (path in ("/", "")):
return path
parent, child = os.path.split(path)
cparent = canonicalpath(parent)
cchild = _canonicalise(child, os.listdir(cparent))
return os.path.join(cparent, cchild)

Or, more crudely, do something like this:

def exists_dontignorecase(path):
dir, f = os.path.split(path)
return f in os.listdir(dir)

But better solutions are welcome.

Thanks,
tom

--
Infantry err, infantry die. Artillery err, infantry die. -- IDF proverb
Jan 3 '06 #1
13 4666
Tom Anderson wrote:
Java has a java.io.File.getCanonicalPath method that does this, but i
can't find an equivalent in python - is there one?


What's wrong with: os.path.normcase(path) ?

--Scott David Daniels
sc***********@acm.org
Jan 3 '06 #2
In article <Pi*******************************@urchin.earth.li >,
Tom Anderson <tw**@urchin.earth.li> wrote:
Afternoon all,

MacOS X seems to have some heretical ideas about the value of case in
paths - it seems to believe that it doesn't exist, more or less, so "touch
foo FOO" touches just one file, you can't have both 'makefile' and
'Makefile' in the same directory,
"os.path.exists(some_valid_path.upper())" returns True even when
"os.path.split(some_valid_path.upper())[1] in
os.listdir(os.path.split(some_valid_path)[0])" returns False, etc
(although, of course, "ls *.txt" doesn't mention any of those .TXT files
lying around).

Strictly speaking, it's not OS X, but the HFS file system that is case
insensitive. You can use other file systems, such as "UNIX File
System". Use Disk Utility to create a disk image and then erase it
(again, using Disk Utility) and put UFS on it. You'll find that "touch
foo FOO" will create two files.

--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.
Jan 3 '06 #3
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is case
insensitive. You can use other file systems, such as "UNIX File
System". Use Disk Utility to create a disk image and then erase it
(again, using Disk Utility) and put UFS on it. You'll find that
"touch foo FOO" will create two files.


You may also find some native Mac OS X applications failing in strange
ways.

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jan 3 '06 #4
Tom Anderson wrote:
Java has a java.io.File.getCanonicalPath method that does this, but i
can't find an equivalent in python - is there one?

I can emulate it like this:


I think it could be implemented more efficiently with getattrlist(2),
looking for ATTR_CMN_NAME. Unfortunately, there appears to be no wrapper
for this function.

Alternatively, you might also find macos.GetFullPathname useful,
although I'm uncertain as to how precisely it is used.

Regards,
Martin
Jan 4 '06 #5
On Tue, 3 Jan 2006, Scott David Daniels wrote:
Tom Anderson wrote:
Java has a java.io.File.getCanonicalPath method that does this, but i can't
find an equivalent in python - is there one?


What's wrong with: os.path.normcase(path) ?


It doesn't work.

Hooke:~ tom$ uname
Darwin
Hooke:~ tom$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import os
path=os.path.join(".", os.listdir(".")[0])
path './.appletviewer' os.path.normcase(path) './.appletviewer' os.path.normcase(path.upper()) './.APPLETVIEWER'


I'm not entirely sure what normcase is supposed to do - the documentation
says "Normalize case of pathname. Has no effect under Posix", which is
less than completely illuminating.

tom

--
It involves police, bailiffs, vampires and a portal to hell under a
tower block in Hackney.
Jan 4 '06 #6
On Tue, 3 Jan 2006, Dan Sommers wrote:
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is case
insensitive.
Aaah, of course. Why on earth didn't Apple move to UFS/FFS/whatever with
the switch to OS X?
You can use other file systems, such as "UNIX File System". Use Disk
Utility to create a disk image and then erase it (again, using Disk
Utility) and put UFS on it. You'll find that "touch foo FOO" will
create two files.


You may also find some native Mac OS X applications failing in strange
ways.


Oh, that's why. :(

tom

--
It involves police, bailiffs, vampires and a portal to hell under a
tower block in Hackney.
Jan 4 '06 #7
>>>>> Doug Schwarz <se*@sig.for.address.edu> (DS) wrote:
DS> In article <Pi*******************************@urchin.earth.li >,
DS> Tom Anderson <tw**@urchin.earth.li> wrote:
Afternoon all,

MacOS X seems to have some heretical ideas about the value of case in
paths - it seems to believe that it doesn't exist, more or less, so "touch
foo FOO" touches just one file, you can't have both 'makefile' and
'Makefile' in the same directory,
"os.path.exists(some_valid_path.upper())" returns True even when
"os.path.split(some_valid_path.upper())[1] in
os.listdir(os.path.split(some_valid_path)[0])" returns False, etc
(although, of course, "ls *.txt" doesn't mention any of those .TXT files
lying around).


DS> Strictly speaking, it's not OS X, but the HFS file system that is case
DS> insensitive. You can use other file systems, such as "UNIX File
DS> System". Use Disk Utility to create a disk image and then erase it
DS> (again, using Disk Utility) and put UFS on it. You'll find that "touch
DS> foo FOO" will create two files.


It seems that with Tiger, HFS+ can be made case-sensitive. I haven't seen
it, only read about it.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Jan 4 '06 #8
Piet van Oostrum wrote:
It seems that with Tiger, HFS+ can be made case-sensitive. I haven't seen
it, only read about it.


Yes, indeed, that is possible. I tried it, once. Right now I'm using
the case insensitive version again, which should tell you how well it
works - the canon utilities of my camera refused to work for me, as did
Audacity. I didn't encounter any other problems, but that was enough
for me.

As to UFS: it is apparently way slower than HFS+, and only recommended
in special cases, most of which are now advised to use Case-sensitive
HFS+, I believe.

Maarten

Jan 4 '06 #9

On 4 Jan 2006, at 02:50, Tom Anderson wrote:
On Tue, 3 Jan 2006, Dan Sommers wrote:
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is
case
insensitive.


You can choose if HFS+ behaves in a case-preserving, case-insensitive
or case-sensitive manner. See man newfs_hfs. Case sensitive is not
supported on the 'System' volume, but I have several external disks
using it without a problem for do general unix-like development
projects.

hth

Michael
Jan 5 '06 #10

On Jan 4, 2006, at 4:32 AM, Michael Anthony Maibaum wrote:
You can choose if HFS+ behaves in a case-preserving, case-insensitive
or case-sensitive manner. See man newfs_hfs. Case sensitive is not
supported on the 'System' volume, but I have several external disks
using it without a problem for do general unix-like development
projects.


For people without an external disk sitting around, note that you can
also do this via a mountable disk image. Here's an example to create
a case-sensitive HFS+ image:

hdiutil create -size 10m -fs "Case-sensitive HFS+" -volname MyVolume
MyVolume.dmg

For more information, try "hdiutil create" or "man hdiutil".

-dan

--
There is nothing new in the world except the history you do not know.
-Harry Truman
Jan 5 '06 #11

On Jan 3, 2006, at 9:50 PM, Tom Anderson wrote:
On Tue, 3 Jan 2006, Dan Sommers wrote:
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is
case
insensitive.
Aaah, of course. Why on earth didn't Apple move to UFS/FFS/whatever
with
the switch to OS X?
You can use other file systems, such as "UNIX File System". Use
Disk
Utility to create a disk image and then erase it (again, using Disk
Utility) and put UFS on it. You'll find that "touch foo FOO" will
create two files.


You may also find some native Mac OS X applications failing in
strange
ways.


Oh, that's why. :(


That's one reason, but here are two more:

1. It would have broken the expected behavior from the previous 15
years of Mac OS releases. Given Mac users' obsessive attention to
detail regarding the consistency of their environment, this would
*not* have gone over well at all.

2. Mac OS is designed primarily for non-technical users. A case-
sensitive filesystem would just be confusing for the main audience.
If I tried to explain to my mother that Dan.doc is not the same as
DAN.DOC, she would probably tell me I was out of my mind.

Think about it - how many things used by average people are case
sensitive? Passwords? That's about it. (And judging by most user
passwords I have seen, they're almost all lowercase anyway.) Email
addresses, URLs, the search box in Google, your AOL or Jabber buddy
list: all case-insensitive.

Aside from that, what is "right" is a matter of opinion. I prefer
case-insensitive filesystems, and I'm a system administrator who
works on Solaris systems all day. Others I work with refuse to
consider case-insensitive filesystems as anything but a "bug". Who's
right? I don't think there's one true answer...

I'm not trying to get into one of these case sensitivity religious
wars here, just offering an opinion.

-dan

--
For a list of all the ways technology has failed to improve the quality
of life, please press three. -Alice Kahn

Jan 6 '06 #12
Dan Lowe <da*@tangledhelix.com> writes:
Think about it - how many things used by average people are case
sensitive? Passwords? That's about it. (And judging by most user
passwords I have seen, they're almost all lowercase anyway.) Email
addresses, URLs, the search box in Google, your AOL or Jabber buddy
list: all case-insensitive.


Not all URLs. Compare, for example:

http://www.python.org/doc/Summary.html
http://www.python.org/doc/summary.html

--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Those who can make you believe absurdities
can make you commit atrocities. - Voltaire
Jan 6 '06 #13

On Jan 6, 2006, at 1:13 PM, Mark Jackson wrote:
Dan Lowe <da*@tangledhelix.com> writes:
Think about it - how many things used by average people are case
sensitive? Passwords? That's about it. (And judging by most user
passwords I have seen, they're almost all lowercase anyway.) Email
addresses, URLs, the search box in Google, your AOL or Jabber buddy
list: all case-insensitive.


Not all URLs. Compare, for example:

http://www.python.org/doc/Summary.html
http://www.python.org/doc/summary.html


You are correct, of course. I was thinking of cases like this:

http://www.python.org
HTTP://WWW.PYTHON.ORG
hTtP://www.PyThOn.ORG

So I should have said "hostnames" instead of "URLs". In my
experience, most URLs that are actually typed in are like this...

http://yahoo.com
http://google.com
http://ebay.com
http://apple.com
http://amazon.com

And in that form, they are not case sensitive. They only become that
way when you start putting more on the end. But I'd guess that 90%+
of the time, URLs of that form are clicked on, not typed into the
browser.

-dan

--
You know you've achieved perfection in design, not when you have
nothing more
to add, but when you have nothing more to take away.
-Antoine de Saint-Exupery
Jan 6 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Lucas-Smith | last post by:
I am trying to take a string and split it into a filename and a number where the number is what follows the *last* instance of a comma in that string. Split and explode won't work because if the...
7
by: deko | last post by:
I need to allow users to download files from a directory that is not publicly accessible. To do this, I use a download script: header("Content-Type: application/octet-stream");...
3
by: S.W. Rasmussen | last post by:
With the risk of being accused of multi-posting I would like to draw the attention to a serious visual basic/windows issue discussed in the microsoft.public.vb.bugs newsgroup. As pointed out below...
10
by: sam | last post by:
Hi, Can anyone tell me how to print a file name from ifstream? the following cout code does not print the filename I created with ifstream preivous: ifstream is; is.open ("text.txt");
4
by: Michael | last post by:
All, I'll asked a question but I was not detailed (clear) enough for people to help so I'll retry. I have a cgi script pass a variable from one page to the next. The 'receiving' page replaces...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
27
by: gmtonyhoyt | last post by:
I need assistance coming up with a clean way to handle filename extensions with my application. While I can come up with several ways of doing so on my own, I felt perhaps it would be worth...
2
by: kinghuangz | last post by:
Everyone: I want to use a DLL(FileName:PubFunction.Dll) built with VS.Net(C#) in a unmanaged Program .But there was a Dll just has the same filename,it was built with VC++(6.0).The unmanaged was...
10
by: Steve | last post by:
I am trying to create a downloader which will bypass the saveas box in the WebBrowser control. I have the file downloading, but I don't know what the filename is that is being passed through the...
16
by: Stef Mientki | last post by:
hello, How can I find the correct case of a filename ? Background in my program I use case sensitive filenames, just like Python requires. Now I've integrated pdb into the program, but pdb...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.