Reminder about cross-platform case-sensitivity differences
This is just a very brief reminder about something you might run into when you’re trying to get your code to work on multiple platforms – in this case, OS X, Linux and Windows.
Basically: file names/paths are case-sensitive on Linux, but not on OS X or Windows.
Therefore, you could have some Python code like this:
f = open(os.path.join(base_path, 'LE72020252003106EDC00_B1.tif'))
which you might use to open part of a Landsat 7 image – and it would work absolutely fine on OS X and Windows, but fail on Linux. I initially assumed that the failure on Linux was due to some of the crazy path manipulation stuff that I had done to get base_path
– but it wasn’t.
It was purely down to the fact that the file was actually called LE72020252003106EDC00_B1.TIF
, and Linux treats LE72020252003106EDC00_B1.tif
and LE72020252003106EDC00_B1.TIF
as different files.
I’d always known that paths on Windows are not case-sensitive, and that they are case-sensitive on Linux – but I’d naively assumed that OS X paths were case-sensitive too, as OS X is based on a *nix backend, but I was wrong.
If you really have problems with this then you could fairly easily write a function that checked to see if a filename exists, and if it found that it didn’t then tried searching for files using something like a case-insensitive regular expression – but it’s probably just easiest to get the case of the filename right in the first place!
If you found this post useful, please consider buying me a coffee.
This post originally appeared on Robin's Blog.
Categorised as: Computing, Linux, OSX, Programming, Python, Windows
Filenames are case-sensitive on OS X too, it’s just that on a standard OS X installation, the filesystem is set to be case-insensitive. But you can install OS X on a filesystem with case-sensitivity enabled too.
Ah thanks Chris – I didn’t know that (I guess I’d only ever seen standard OS X installations). I’ll update the post.
I had not know that about OSX. I’ve been using the command line for years now, and didn’t notice. probably because i almost never use upper case in file names.