Reading file names with case insensitivity

Hello I do a decent amount of Matlab programming in both Windows and Linux, and also use Dropbox of my means for sharing files between both operating systems.
When I save an stl file in windows it saves it as example.stl when I open that file again in Linux it makes it example.STL This forces me to either rename every stl file to be lowercase when I am in Linux or to switch my Matlab code to have stl uppercase.
Is there a way I can read in file names and not be case sensitive?

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 4 Mär. 2014
Bearbeitet: Mischa Kim am 4 Mär. 2014

1 Stimme

You could use the lower command to convert the file name string to lower case, before opening the file.
lower('example.STL')
ans =
example.stl

3 Kommentare

Right. When I need to check on a certain filename, like I'm processing a list and I want to do something special when I get to a certain file, I cast to lower.
if strfind(lower(filename), 'calibration') > 0
% Calibration is in the filename so do something special...
If you're using strcmp(), you can use strcmpi() instead.
Ryan
Ryan am 5 Mär. 2014
It ended up working fine on Windows (where example.stl was) but did not work on Linux (where exmaple.STL), I ended up using this instead:
if exist('example.stl')~=2 pelvis = stlread('example.STL'); else pelvis = stlread('example.stl'); end
It looks a little messy but works fine, only thing now is its giving me a warning that for the exist command I should give it a data type, but I was unable to find on what data type to use for stl files with Matlab
Try
exist('example.stl', 'dir')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 4 Mär. 2014

Kommentiert:

am 5 Mär. 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by