Use dir with a defined string AND wildcard?

조회 수: 32 (최근 30일)
Paxton Carnes
Paxton Carnes 2017년 5월 24일
댓글: Paxton Carnes 2017년 5월 24일
I am trying to search through roughly 2000 .csv files to find the one that matches user input. The user input is in the form of a string, so I have a string 'R' that I want to include in my DIR search. I also want to use the wildcard '*' in the DIR function because the file names are much more complex than the user input 'R'. Is there a way to search my files using both a predefined string 'R' and wildcard? I know I could use a string and wildcard together in the form DIR('*filesearch'), but I want to utilize user input from a GUI rather than have the user go into the code and include their search words explicitly in the DIR function.

채택된 답변

the cyclist
the cyclist 2017년 5월 24일
편집: the cyclist 2017년 5월 24일
Is it as simple as
R = 'user_stuff'; % Get this from user input
dir(['*',R])
or maybe
dir(['*',R,'*'])
  댓글 수: 1
Paxton Carnes
Paxton Carnes 2017년 5월 24일
Worked perfectly! I had tried this solution without the brackets, but had the error of too many input arguments. The square brackets made it work though. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by