필터 지우기
필터 지우기

Deleting Files in other folders with different names

조회 수: 4 (최근 30일)
Adrian Pielmeier
Adrian Pielmeier 2018년 9월 3일
편집: Stephen23 2018년 9월 3일
Hello to all!
My matlabcode .m is in an specific folder. In the Same Folder there are two Folders. These two folders have every Time I execute the Matlab code Different names. The only thing that remanes the same is the ending of the folders for example:
Sample1_data
Sample2_data
and the next time the folders names are
test1_data
test2_data
So my question is. How can i get my matlab code running like this:
Go in the first *_data folder and delete expample.png
go to second *_data folder and delete example.png
I hope you guys understand what i want. My english is not very good
Thanks to all!
  댓글 수: 2
Stephen23
Stephen23 2018년 9월 3일
@Adrian Pielmeier: what MATLAB version are you using?
Adrian Pielmeier
Adrian Pielmeier 2018년 9월 3일
MATLAB R2016b

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

답변 (1개)

Stephen23
Stephen23 2018년 9월 3일
편집: Stephen23 2018년 9월 3일
This should get you started (untested):
S = dir('*_data');
N = {S([S.isdir]).name};
for k = 1:numel(N)
F = fullfile(N{k},'example.png');
delete(F)
end
The documentation describes looping over files, but the same applies to looping over folders:

카테고리

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