필터 지우기
필터 지우기

How to delete the ending / last characters of files?

조회 수: 9 (최근 30일)
Haron Shaker
Haron Shaker 2021년 3월 23일
댓글: Haron Shaker 2021년 4월 9일
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?

채택된 답변

Rashed Mohammed
Rashed Mohammed 2021년 3월 26일
편집: Rashed Mohammed 2021년 3월 26일
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
Rashed Mohammed
Rashed Mohammed 2021년 3월 26일
Thanks Rik for pointing out the bug. Updated the code
Haron Shaker
Haron Shaker 2021년 4월 9일
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

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by