how to rename files .tif in a folder ?

조회 수: 9 (최근 30일)
Ade Aulya
Ade Aulya 2018년 12월 11일
댓글: Stephen23 2018년 12월 11일
hi.. does anyone can help me with this code, please ? it's created by Jiro Doke. it were run but i didn't get the name file as i want. i wanted to change those file's number into only 1,2,3,4,5,and so on.. FYI, i've tried to change the folder name like this..
% Get all files in the current folder clear all;
files = dir(fullfile('C:\Users\ASUS\Desktop\2','*.tif'));
% Loop through each
for id = 1:length(files)
% Get the file name (minus the extension)
[~, f] = fileparts(files(id).name);
% Convert to number
num = str2double(f);
if ~isnan(num)
% If numeric, rename
APath = fullfile('C:\Users\ASUS\Desktop\2', files(id).name);
movefile(APath, sprintf('%d.tif', num));
end
end
and the output files name were like this :
2.100000e+00.tif
2.100100e+00.tif
2.100200e+00.tif
2.100300e+00.tif
2.100400e+00.tif
2.100500e+00.tif
etc..
or if i want to change it like
1a
2a
3a
continue directly to
5b
6b
7b
and so on..
what should i do, please ?
thank you so much.
  댓글 수: 3
Ade Aulya
Ade Aulya 2018년 12월 11일
i mean. i have a folder but the files in that folder are from multiple folder. and i want to create the name of that files like this :
1
2
3
4
5
but adding the sign of those files such as number 1 - 3 are from folder image a and number 4-5 are from folder image b, etc..
Stephen23
Stephen23 2018년 12월 11일
Sure, just add the "folder image" names onto the new file names.

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

채택된 답변

Stephen23
Stephen23 2018년 12월 11일
편집: Stephen23 2018년 12월 11일
D = 'C:\Users\ASUS\Desktop\2';
S = dir(fullfile(D,'*.tif'));
for k = 1:numel(S)
[~,F] = fileparts(S(k).name);
if ~isnan(str2double(F))
old = fullfile(D,S(k).name);
new = sprintf('%d.tif',k)
movefile(old,new);
end
end
  댓글 수: 1
Ade Aulya
Ade Aulya 2018년 12월 11일
Sir, it works !
thankyou so much for your help :)
thank you..

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by