converting .001 .002 file

7 ビュー (過去 30 日間)
Dom Smith
Dom Smith 2016 年 11 月 28 日
コメント済み: Dom Smith 2016 年 11 月 29 日
I have a folder of several hundred files with extensions .001 .002 etc How can I rename them such that I retain the detail in the extension but convert them to a more usable file format such as .m file or .txt
So an example of the current filenames:
PUVT0000.000
PUVT0000.001
PUVT0000.002
PUVT0000.003
PUVT0001.002
PUVT0001.004
PUVT0001.005
PUVT0002.004
and what the desired filename:
PUVT0000_000.txt
PUVT0000_001.txt
PUVT0000_002.txt
PUVT0000_003.txt
PUVT0001_002.txt etc.

採用された回答

KSSV
KSSV 2016 年 11 月 28 日
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 11 月 28 日
If you look at that solution, KSSV included a line
[~, f] = fileparts(files(id).name);
fileparts() can also have a third output, which is the file extension. You can create a new name from f and the file extension:
orig_name = files(id).name;
[~, basename, ext] = fileparts(orig_name);
new_name = [basename '_', ext(2:end) '.txt'];
movefile(orig_name, new_name);
Dom Smith
Dom Smith 2016 年 11 月 29 日
Ahh legend, thank you both very much

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2016 年 11 月 28 日
Get a list of all the files. dir will do that.
help dir
Then, rename each file, using a loop over the files. Just create the new name in each case from the old, as a string. WTP?

カテゴリ

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