Thursday, 15 May 2014

sorting - Odd numbering of files from one folder to other in matlab -



sorting - Odd numbering of files from one folder to other in matlab -

files nowadays in 1 folder:

1 copy(1).jpg,

1 copy(2).jpg

.......

.......

.......

1 copy(800)

odd numbering of files , save in other folder.desired output shown below:

1.jpg,

3.jpg,

5.jpg

....

....

....

799.jpg

source code tried:

a ='c:\users\rahul\desktop\jumbled test\copiedimages\'; =dir( fullfile(a, '*.jpg') ); filenames = { a.name }; ifile = 1 : numel( ) newname = fullfile(a, sprintf( '%d.jpg',ifile+2) ); movefile( fullfile(a, filenames{ ifile }), newname ); end

but cant able desired output.so solution?

don't rename files, move them new directory after checking if had odd number in file name:

a ='c:\users\rahul\desktop\jumbled test\copiedimages\'; destination = ='c:\users\rahul\desktop\jumbled test\copiedimages\odd\'; =dir( fullfile(a, '*.jpg') ); filenames = { a.name }; ifile = 1 : numel( ) [~,name] = fileparts(filenames{ ifile }); %// part might not necessary if filenames{ ifile } file name without directory. in case rather utilize name=filenames{ ifile }; %// extract number file name filenum = str2num(name(8:end-4)); %// check if number odd if mod(filenum,2) == 1 movefile(fullfile(a, filenames{ ifile }), fullfile(destination, filenames{ ifile })); end end

matlab sorting for-loop dir

No comments:

Post a Comment