% [DefFilePath]=SetDefPath('r','*.*');
% [NFiles,FileMat,VersionString,BatchFilePath]=ReadFileNames(FileMat,DefFilePath,'Get MRI file(s)');
% if NFiles==0; return; end
% SetDefPath('w',BatchFilePath);

%   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.                                                                      
NFiles=72



Path='Paul:fMRIData:fMRIDataGV:03:Orig:01:';
File=['03.01.'];

for FileInd=6:NFiles
	if FileInd<10
		OldExt=['00' int2str(FileInd) '.img'];
	else
		OldExt=['0' int2str(FileInd) '.img'];
	end
	OldFilePath=['"' Path,File,OldExt '"']
	if FileInd<15
		if FileInd<5
			NewExt=['00' int2str(FileInd) '.imgtmp'];
		else
			NewExt=['00' int2str(FileInd-4) '.img'];
		end
	else
		NewExt=['0' int2str(FileInd-4) '.img'];
	end
	NewFile=['"' File,NewExt '"']
	RenameResult = applescript('arename', 'itemName', OldFilePath, 'newName', NewFile);
	fprintf('Picture: %g of %g; \n',FileInd,NFiles);
	fprintf('Result of arename:  '); fprintf(RenameResult); fprintf('\n');
	fprintf('Renamed File:  '); fprintf(NewFile); fprintf('\n');
	
	if FileInd<10
		OldExt=['00' int2str(FileInd) '.hdr'];
	else
		OldExt=['0' int2str(FileInd) '.hdr'];
	end
	OldFilePath=['"' Path,File,OldExt '"']
	if FileInd<15
		if FileInd<5
			NewExt=['00' int2str(FileInd) '.hdrtmp'];
		else
			NewExt=['00' int2str(FileInd-4) '.hdr'];
		end
	else
		NewExt=['0' int2str(FileInd-4) '.hdr'];
	end
	NewFile=['"' File,NewExt '"']
	RenameResult = applescript('arename', 'itemName', OldFilePath, 'newName', NewFile);
	fprintf('Picture: %g of %g; \n',FileInd,NFiles);
	fprintf('Result of arename:  '); fprintf(RenameResult); fprintf('\n');
	fprintf('Renamed File:  '); fprintf(NewFile); fprintf('\n');
	
end
