Using dir() without changing directory?
Mostra commenti meno recenti
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?
6 Commenti
Geoff Hayes
il 11 Ott 2019
Zeynab - rather than changing directories, why not just include the full path to that folder that has those files that you are looking for? Use that full path when calling dir.
Zeynab Mousavikhamene
il 11 Ott 2019
Geoff Hayes
il 11 Ott 2019
The full path to your folder could be something like
dir(['/users/geoffh/someFolder/*K1*.json'])
or whatever is appropriate for your platform.
Zeynab Mousavikhamene
il 11 Ott 2019
Modificato: Zeynab Mousavikhamene
il 11 Ott 2019
Jim Riggs
il 11 Ott 2019
Perhaps you did not understand:
The path specification "/users/geoffh/someFolder/" represents the full path to the folder that contains the files that you want to search. You need to substitude the actual path to your files.
If you specify a path in the 'dir' command, it will searth that specified folder.
"I prefere not to change directory because I will get error while running the script. "
Changing folders to access data files is slow and makes the code harder to debug. Best avoided.
It is much better to use absolute/relative filenames, as the others have already commented.
"the folder containing *K1*.json is differnt from matlab running script... I need a structure that can define the folder containing K1.json files."
That is exactly what absolute/relative filenames are for:
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!