%   RenameValAro.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.  

NCond=5
NPicPerBlock=36
RandBlock=ReadAscii;
BasePath=['Paul:Movies:Giessen:ValAro36:']
NewPath='Paul:Movies:Giessen:ValAro36N:'
                                                                    
NBlock=length(RandBlock);
Count1=0;
Count2=0;
Count3=0;
Count4=0;
Count5=0;
PicIndTmp=1800;
RandVec=randperm(NPicPerBlock)
SaveAscii(RandVec)
for BlockInd=51:NBlock
	BlockInd=BlockInd
	if RandBlock(BlockInd)==1
		Count1=Count1+1;
		if Count1>10; Count1=1; end
		if Count1<10
			BlockIndStr=['Neut0',int2str(Count1)];
		else
			BlockIndStr=['Neut',int2str(Count1)];
		end
		Test='Neut'
	elseif RandBlock(BlockInd)==2
		Count2=Count2+1;
		if Count2>10; Count2=1; end
		if Count2<10
			BlockIndStr=['NVHA0',int2str(Count2)];
		else
			BlockIndStr=['NVHA',int2str(Count2)];
		end
		Test='NVHA'
	elseif RandBlock(BlockInd)==3
		Count3=Count3+1;
		if Count3>10; Count3=1; end
		if Count3<10
			BlockIndStr=['NVLA0',int2str(Count3)];
		else
			BlockIndStr=['NVLA',int2str(Count3)];
		end
		Test='NVLA'
	elseif RandBlock(BlockInd)==4
		Count4=Count4+1;
		if Count4>10; Count4=1; end
		if Count4<10
			BlockIndStr=['PVHA0',int2str(Count4)];
		else
			BlockIndStr=['PVHA',int2str(Count4)];
		end
		Test='PVHA'
	elseif RandBlock(BlockInd)==5
		Count5=Count5+1;
		if Count5>10; Count5=1; end
		if Count5<10
			BlockIndStr=['PVLA0',int2str(Count5)];
		else
			BlockIndStr=['PVLA',int2str(Count5)];
		end
		Test='PVLA'
	end
	OldPath=[BasePath,BlockIndStr,':']
	for PicIndInd=1:NPicPerBlock
		PicInd=RandVec(PicIndInd);
		PicIndTmp=PicIndTmp+1;
		if PicInd<10
			OldFile=['00' int2str(PicInd) '.jpg'];
		elseif PicInd>9 & PicInd<100
			OldFile=['0' int2str(PicInd) '.jpg'];
		elseif PicInd>99 & PicInd<1000
			OldFile=[int2str(PicInd) '.jpg'];
		end
		OldFilePath=['"' OldPath,OldFile '"']

		if PicIndTmp<10
			NewFile=['000' int2str(PicIndTmp) '.jpg'];
		elseif PicIndTmp>9 & PicIndTmp<100
			NewFile=['00' int2str(PicIndTmp) '.jpg'];
		elseif PicIndTmp>99 & PicIndTmp<1000
			NewFile=['0' int2str(PicIndTmp) '.jpg'];
		elseif PicIndTmp>999 & PicIndTmp<10000
			NewFile=[int2str(PicIndTmp) '.jpg'];
		end
		
		CopyResult=applescript('acopy','itemName',OldFilePath,'folderName',['"' NewPath '"']);
		
		CopyFilePath=['"' NewPath,OldFile '"'];
		NewFile=['"' NewFile '"'];
		RenameResult = applescript('arename','itemName',CopyFilePath,'newName',NewFile);
		fprintf('Picture: %g of %g; \n',PicInd,NPicPerBlock);
		fprintf('Result of acopy:  '); fprintf(CopyResult); fprintf('\n');
		fprintf('Copied File:  '); fprintf(OldFile); fprintf('\n');
		fprintf('Result of arename:  '); fprintf(RenameResult); fprintf('\n');
		fprintf('Renamed File:  '); fprintf(NewFile); fprintf('\n');
	end
end
