How to search a keyword from files of a folder and if found, check if the filename written just after it is present in entire folder or not??

조회 수: 5 (최근 30일)
Hello all,
I got stuck in a problem, please help.
I am trying to search a keyword "import from" inside many .art files present in a folder. if found, check if the filename written just after it is present in entire folder or not. For example - suppose it is written import from "abc_efg_xyz.art" inside a file. Here, after searching i will get to know that it has "import from" keyword.what should i do to check if "abc_efg_xyz.art" file is present in entire folder or not??

채택된 답변

Image Analyst
Image Analyst 2021년 3월 14일
See the FAQ:
Inside the loop over all files, do something like
fileContents = fileread(fullFileName);
if contains(fileContents, '"import from', 'IgnoreCase', true)
% Do something...like store which index or filename has the phrase.
end
"present in entire folder or not" is ambiguous. Do you want to see if EVERY file in the folder has that phrase, or if ANY file in the folder has that phrase. If any, then just break out of the loop once you find it.
fileContents = fileread(fullFileName);
foundIt = false;
if contains(fileContents, '"import from', 'IgnoreCase', true)
foundIt = true; % Quit once any file has this.
break;
end
  댓글 수: 1
Rohit P
Rohit P 2021년 3월 14일
Thank u so much for replying.
Actually i have to search for keyword "import from" in every file. And if the match is found.write the part just after it in an excel file. For Ex if it is written import from xyz_abc.art in a file.i have to write a code such that i will be able to write part just after it.i.e xyz_abc.art in an excel file.
Can you help me in this part?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by