MATLAB: Using dir() without changing directory

cddir

I need to find files that have dir(['*K1*.json']); in their names which are in a specific folder different from the matlab script folder. I prefere not to change directory because I will get error while running the script.
Is there any way to do so?

Best Answer

Use an absolute path rather than a relative path (as proposed in the comments). It's easier to get it right. Thus try
sad = dir( fullfile( 'c:', 'specific', 'folder', ['*K1*.json'] ) );