Can Matlab search through the current directory to find and import a file?

10 visualizzazioni (ultimi 30 giorni)
I have some scripts that do data analysis and I am hoping to write some preliminary code to go through the current folder and find a .csv file and then import it and then I would like to go through another folder and search for a '...SizeChem.dat' file without knowing the full name of the file only knowing that it is the only file that ends with SizeChem.dat. I am not sure if this is possible or not but would greatly appreciate the help.

Risposta accettata

Cam Salzberger
Cam Salzberger il 13 Giu 2019
Hey Noah,
You can use the dir function to get information on the contents of a folder. You can use wildcards (* or **) to match multiple possible files. For example, dir('*.csv') will match all CSV files in the current directory. And you could do dir('path/to/other/dir/*SizeChem.dat') to match your other file (if you know the folder it should be in). If you need to search through multiple folders, you can simply loop through them, checking if any matches were found (with dir or even exist).
-Cam

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by