Effacer les filtres
Effacer les filtres

search for a folder from a different directory

18 vues (au cours des 30 derniers jours)
Arcot
Arcot le 26 Août 2022
Modifié(e) : Stephen23 le 26 Août 2022
I have an issue with searching for a folder in a directory. This is a 2-part question and is as follows,
  1. I have a directory which has about a 100 folders which are named after the date it was created. The format of the date is "yyyy-MM-dd". Now, I have to check if a folder exists in the directory matching a partiular date. i.e., for example I have to check if a folder with name '2022-05-24' exists in the directory
  2. How can I do the same if the directory is not the parent directory i.e., the folder is not ny current folder on MATLAB.
Let me know if any further clarification is necessary.
Thank you in advance.

Réponses (2)

Chunru
Chunru le 26 Août 2022
Modifié(e) : Chunru le 26 Août 2022
cfolder = pcd;
cd YourRootFolder
a = dir ("**/2022-05-24.*"); % ** for subfolders
isempty(a)
cd cfolder

Stephen23
Stephen23 le 26 Août 2022
Modifié(e) : Stephen23 le 26 Août 2022
Using CD is slow and makes code harder to debug. The efficient approach is to use absolute/relative filenames.
The best approach would be to use FULLFILE and ISFOLDER:
P = 'absolute or relative path to where those folders are';
D = '2022-05-24';
X = isfolder(fullfile(P,D))

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by