Code to rename fiiles
1 回表示 (過去 30 日間)
古いコメントを表示
I am looking to rename files that are titled "Untitled.0001.jpg" to 1,2,3...,n.jpg
I have a bunch of files that get spit out from a program in that format, but just want to name them by a number. How would I go about doing that?
0 件のコメント
回答 (1 件)
Azzi Abdelmalek
2016 年 8 月 10 日
編集済み: Azzi Abdelmalek
2016 年 8 月 10 日
f='Untitled.0001.jpg'
nf=regexprep(f,'(\S+\.)(\d+)(\.jpg)','${num2str(str2num($2))}$3')
Or
f='Untitled4.0201.jpg'
nf=regexp(f,'[1-9]\d+\>.jpg','match','once')
To rename the file
folder='C:\Users\you\Documents\MATLAB' % folder where your jpg are located
filetype=fullfile(folder,'*.jpg')
file=dir(filetype)
filename={file.name}
for k=1:numel(file)
f=filename{k}
nf=regexp(f,'[1-9]\d+\>.jpg','match','once')
move(fullfile(folder,f),fullfile(folder,nf))
end
3 件のコメント
Image Analyst
2016 年 8 月 11 日
To run, type the F5 key or click the green Run triangle on the tool ribbon.
To master MATLAB, see this http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!