Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Rename and recount files in a loop
Replies: 9   Last Post: Oct 9, 2013 11:33 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Engineer

Posts: 26
Registered: 1/19/12
Rename and recount files in a loop
Posted: Sep 30, 2013 7:44 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Howdy!

I am trying to rename and recount a list of grabbed frames. I would like to do rename those with the exact time.
File's name is structured like yyyy-mm-gg_hh-mm-ss_framenumber.
In particular, frame number has to be between 0 and 7(here I stopped), and after that the number of seconds must to increase, and following also the minutes (after 59 minutes) and so on.

Can somebody help me, please?

close all
clear all
clc
a ='C:\Path';
A =dir( fullfile(a, '*.bmp') );
fileNames = { A.name };

dates = char(fileNames);
dates(:,1:3) = []; %Remove first four random characters
date=dates(:,1:10);
time = dates(:,12:17); %Remove file extension
frame=dates(:,19:21);
datesT=dates(:,1:17);
dates= datenum(datesT,'yyyy-mm-dd_HHMMSS'); %Convert date strings to matlab format

for iFile = 1 : numel( A )

[PATH,NAME,EXT] = fileparts(A(iFile).name);
oldName=[NAME,EXT];
yy=[NAME(4) NAME(5) NAME(6) NAME(7)];
mth=[NAME(9) NAME(10)];
gg=[NAME(12) NAME(13)];
hh=[NAME(15) NAME(16)];
mm=[NAME(17) NAME(18)];
ss=[NAME(19) NAME(20)];
frame=[NAME(22) NAME(23) NAME(24)];
hhN=str2double(hh);
mmN=str2double(mm);
ssN=str2double(ss);
frameN=str2double(frame);

for k=0:7
newName = [yy mth gg '_' hh mm ss '_' num2str(k) ,EXT];
end

%copyfile(oldName,newName);

end



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.