Borrar filtros
Borrar filtros

How to search pathname for string

1 visualización (últimos 30 días)
Aadil
Aadil el 22 de Ag. de 2012
Hi,
I'm using this code to give the filepath of the selected file:
[FileName,PathName,FilterIndex] = uigetfile
PathName = T:\Field Test\Field Test Scripts\Master Files\For Single Screen File\Final Combined Script\OLD\
Now I want to search this pathname for 'OLD', so I used this code:
strcmpi(PathName, 'OLD')
But it always returns false:
ans =
0
What am I doing wrong?
Thanks,

Respuesta aceptada

José-Luis
José-Luis el 22 de Ag. de 2012
Editada: José-Luis el 22 de Ag. de 2012
You are comparing two strings for equality, and the comparison is not case sensitive (help strcmpi). What you wanted to do, I guess, is to find out if a string is included in another string. For that i would recommend:
isFound = ~isempty(regexp(Pathname,'OLD'));
Cheers!
  3 comentarios
José-Luis
José-Luis el 22 de Ag. de 2012
My pleasure!
Jan
Jan el 22 de Ag. de 2012
Faster:
isFound = strfind(Pathname, 'OLD')
Safer:
isFound = strfind(fullfile(Pathname, filesep), [filesep, 'OLD', filesep])
This avoids a false match for "C:\Temp\REINHOLD\newData\".

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by