rename part of a file names in folder

2 ビュー (過去 30 日間)
Boby S
Boby S 2020 年 9 月 14 日
コメント済み: Boby S 2020 年 9 月 15 日
Hi
I have a folder with many files. The file names start like 'd10-raw-LT-4000 ...' but the file names end with different charachters and formats.
I want to remove "raw-LT" from my all file names and rename them again. I do not want to change the rest of the name and other properties.

採用された回答

Ruger28
Ruger28 2020 年 9 月 14 日
編集済み: Ruger28 2020 年 9 月 14 日
Use regexprep
FileName = 'd10-raw-LT-4000_xyz123.txt';
FileName = regexprep(FileName,'raw-LT-','');
% Output
FileName =
'd10-4000_xyz123.txt'
To save the file, try:
FileName = 'd10-raw-LT-4000_xyz123.txt';
NewFileName = regexprep(FileName,'raw-LT-','');
movefile(FileName,NewFileName,'f'); % renames the file
Note: you must be in the current folder, or use the entire file path in the FileName.
  1 件のコメント
Boby S
Boby S 2020 年 9 月 15 日
Thanks Ruger
One error I got when one file doesnot meet the rule for file name.
I think I should use 'if'.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by