%   RenDel.m

%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.


ImPath='Movie:N10Pics:';
NIdentPicOld=6;
NIdentPicNew=2;
NPic=704;
IdentIndNew=0;
                                                                      
for PicInd=22:NPic
	for IdentIndOld=1:NIdentPicOld
		PicIndTmp=(PicInd-1).*NIdentPicOld+IdentIndOld;
		if PicIndTmp<10
			OldFile=['File.000' int2str(PicIndTmp)'];
		elseif PicIndTmp>9 & PicIndTmp<100
			OldFile=['File.00' int2str(PicIndTmp)];
		elseif PicIndTmp>99 & PicIndTmp<1000
			OldFile=['File.0' int2str(PicIndTmp)];
		elseif PicIndTmp>999 & PicIndTmp<10000
			OldFile=['File.' int2str(PicIndTmp)];
		end
		if IdentIndOld>NIdentPicNew
			IdentIndNew=0;
			FilePathOld=char([ImPath,OldFile]);
			delete([FilePathOld])
			fprintf('Delete file:  '); fprintf(FilePathOld); fprintf('\n');
		else
			FilePathOld=['"' ImPath,OldFile '"'];
			IdentIndNew=IdentIndNew+1;
			PicIndTmp=(PicInd-1).*NIdentPicNew+IdentIndNew;
			if PicIndTmp<10
				NewFile=['Tmp.000' int2str(PicIndTmp)'];
			elseif PicIndTmp>9 & PicIndTmp<100
				NewFile=['Tmp.00' int2str(PicIndTmp)];
			elseif PicIndTmp>99 & PicIndTmp<1000
				NewFile=['Tmp.0' int2str(PicIndTmp)];
			elseif PicIndTmp>999 & PicIndTmp<10000
				NewFile=['Tmp.' int2str(PicIndTmp)];
			end
			NewFile=['"' NewFile '"'];
			RenameResult = applescript('arename', 'itemName', FilePathOld, 'newName', NewFile);
			fprintf('Picture: %g of %g; IAPS #: %g; File #: %g; Ident.: %g\n',PicInd,NPic);
			fprintf('Result of arename:  '); fprintf(RenameResult); fprintf('\n');
			fprintf('Renamed File:  '); fprintf(NewFile); fprintf('\n');
		end
	end
end

for PicInd=1:NPic
	for IdentInd=1:NIdentPic
		PicIndTmp=(PicInd-1).*NIdentPic+IdentInd;
		if PicIndTmp<10
			OldFile=['Tmp.000' int2str(PicIndTmp)'];
		elseif PicIndTmp>9 & PicIndTmp<100
			OldFile=['Tmp.00' int2str(PicIndTmp)];
		elseif PicIndTmp>99 & PicIndTmp<1000
			OldFile=['Tmp.0' int2str(PicIndTmp)];
		elseif PicIndTmp>999 & PicIndTmp<10000
			OldFile=['Tmp.' int2str(PicIndTmp)];
		end
		if PicIndTmp<10
			NewFile=['File.000' int2str(PicIndTmp)'];
		elseif PicIndTmp>9 & PicIndTmp<100
			NewFile=['File.00' int2str(PicIndTmp)];
		elseif PicIndTmp>99 & PicIndTmp<1000
			NewFile=['File.0' int2str(PicIndTmp)];
		elseif PicIndTmp>999 & PicIndTmp<10000
			NewFile=['File.' int2str(PicIndTmp)];
		end
		FilePathOld=['"' ImPath,OldFile '"'];
		NewFile=['"' NewFile '"'];
		RenameResult = applescript('arename', 'itemName', FilePathOld, 'newName', NewFile);
			fprintf('Picture: %g of %g; \n',PicInd,NPic);
			fprintf('Result of arename:  '); fprintf(RenameResult); fprintf('\n');
			fprintf('Renamed File:  '); fprintf(NewFile); fprintf('\n');
		end
	end
end
return;

return;
