How to delete the ending / last characters of files?

12 ビュー (過去 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 Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by