Home > vbmeg > functions > common > utility > vb_util_change_extension.m

vb_util_change_extension

PURPOSE ^

change extension from the original one to specified one

SYNOPSIS ^

function [new_file] = vb_util_change_extension(org_file, new_ext)

DESCRIPTION ^

 change extension from the original one to specified one
 [usage]
   [new_file] = vb_util_change_extension(org_file, new_ext)
 [input]
   org_file : <required> original file path
    new_ext : <required> new extension
            :  e.g. '.aaa.mat' or 'aaa.mat'
 [output]
   new_file : new file path
 [note]
   if extension period is lost, this program would add it
 [history]
   2007-01-29 (Sako) initial version
   2007-06-22 (Sako) replace fileparts to vb_get_file_parts (for MATLAB7.4.0)

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [new_file] = vb_util_change_extension(org_file, new_ext)
0002 % change extension from the original one to specified one
0003 % [usage]
0004 %   [new_file] = vb_util_change_extension(org_file, new_ext)
0005 % [input]
0006 %   org_file : <required> original file path
0007 %    new_ext : <required> new extension
0008 %            :  e.g. '.aaa.mat' or 'aaa.mat'
0009 % [output]
0010 %   new_file : new file path
0011 % [note]
0012 %   if extension period is lost, this program would add it
0013 % [history]
0014 %   2007-01-29 (Sako) initial version
0015 %   2007-06-22 (Sako) replace fileparts to vb_get_file_parts (for MATLAB7.4.0)
0016 %
0017 % Copyright (C) 2011, ATR All Rights Reserved.
0018 % License : New BSD License(see VBMEG_LICENSE.txt)
0019 
0020 % --- CHECK ARGUMENTS --- %
0021 if ~exist('org_file', 'var'), org_file = ''; end;
0022 if ~exist('new_ext', 'var'), new_ext = ''; end;
0023 [org_file, new_ext] = inner_check_arguments(org_file, new_ext);
0024 
0025 % --- MAIN PROCEDURE --------------------------------------------------------- %
0026 %
0027 new_file = [];
0028 % [org_path, org_name_tmp, org_ext] = fileparts(org_file);
0029 [org_path, org_name_tmp, org_ext] = vb_get_file_parts(org_file);
0030 
0031 if isempty(org_path), org_path = '.'; end;
0032 org_name = vb_util_get_file_body(org_name_tmp);
0033 new_file = [org_path filesep org_name new_ext];
0034 %
0035 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0036 
0037 % --- INNER FUNCTIONS -------------------------------------------------------- %
0038 %
0039 function [org_file, new_ext] = inner_check_arguments(org_file, new_ext)
0040 if isempty(org_file), error('org_file is a required parameter'); end;
0041 if isempty(new_ext), error('new_ext is a required parameter'); end;
0042 
0043 % if extension period is lost, add it here
0044 if new_ext(1) ~= '.', new_ext = ['.' new_ext]; end;
0045 %
0046 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0047 
0048 %%% END OF FILE %%%

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005