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

조회 수: 15 (최근 30일)
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.

채택된 답변

Cam Salzberger
Cam Salzberger 2019년 6월 13일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by