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

9 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Cam Salzberger
Cam Salzberger am 13 Jun. 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

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by