How to delete the ending / last characters of files?

11 visualizaciones (últimos 30 días)
Haron Shaker
Haron Shaker el 23 de Mzo. de 2021
Comentada: Haron Shaker el 9 de Abr. de 2021
Dear all,
I got a list of '...edf.html' files (e.g. 00014654_s001_t000.edf.html).
I want to delete for all files the '.html' part. How can I do it?

Respuesta aceptada

Rashed Mohammed
Rashed Mohammed el 26 de Mzo. de 2021
Editada: Rashed Mohammed el 26 de Mzo. de 2021
Hi Haron
As suggested by Stephen, you can use fileparts and movefile functions to delete the '.html' part from your filenames. Below is a sample code.
files = dir('*.edf.html');
for ii=1:length(files)
oldname = files(ii).name;
[path,newname,ext] = fileparts(oldname);
movefile(oldname,newname);
end
Hope this helps
  3 comentarios
Rashed Mohammed
Rashed Mohammed el 26 de Mzo. de 2021
Thanks Rik for pointing out the bug. Updated the code
Haron Shaker
Haron Shaker el 9 de Abr. de 2021
files = dir('/Users/haron/Desktop/Work/Haron/aprikose_edfs/*.edf.html');
for ii=1:length(files)
oldname = fullfile(files(ii).folder,files(ii).name);
[path,newname,ext] = fileparts(oldname);
movefile(oldname,fullfile(path, newname));
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by