MATLAB Answers

0

How to delete this files..?

Asked by Lalit Patil on 21 Feb 2013
 f=dir(['*.txt'])
f={f.name}
n=find(strcmp(f,'Data.txt'));
f{n}=[]
for k=1:numel(f);
  delete([f{k}])
end

When i execute this program, most of the text files are deleted. But some are not and gives notice like as follow :

 Warning: File not found or permission denied 

Is there any way to overcome this..? Even i want to delete it..

  1 Comment

Jan Simon
on 21 Feb 2013

You can omit the square braces around the strings:

f=dir('*.txt')
delete(f{k})

This saves processing time.

Tags

Products

No products are associated with this question.

2 Answers

Answer by Thorsten
on 21 Feb 2013

Ensure that you have the permission to delete the files.

  0 Comments


Answer by Sean de Wolski
on 21 Feb 2013

Also make sure that the files aren't open in MATLAB or another program.

  2 Comments

Yes those are open in MATLAB. So, i can close that and then can go ahead..

So, how to close this multiple all files.?

If the files are opened, i.e. by MATLAB you can either:

  • fclose('all');
  • Close and restart ML

If they're open in the editor, you can close the Edtior Window, or run this shortcut:

function CloseNoPrompt
%Close all editor windows without prompting
%Active Editor;
hEditor = matlab.desktop.editor.getActive;
%Close all files.
while ~isempty(hEditor);
  closeNoPrompt(hEditor);
  hEditor = matlab.desktop.editor.getActive;
end

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!