Get file names for specified directory with specified basename and extension --- Usage [pathname, filename] = vb_get_session_filename(datadir,basename,ext) [pathname, filename] = ... vb_get_session_filename(datadir,basename,ext,session,mode) --- Input datadir : data directory name ex. 'D:/data/eeg' basename : file basename ex. 'SK' , '' ext : file extension ex. '.bdf' --- Optional Input session : session number list if session is given, filename is generated by using [datadir, basename, ext, session] mode : file name generation mode --- Output pathname : cell array of path for multiple files pathname{n} = [datadir '/' filename{n} ext]; filename : cell array of multiple file names without extension 'ext' if session is given filename{n} = [basename, sprintf('_%d', session(n))]; for mode=0 filename{n} = [basename, sprintf('_%02d',session(n))]; for mode=1 Masa-aki Sato 2008-08-14 Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [pathname, filename] = ... 0002 vb_get_session_filename(datadir,basename,ext,session,mode) 0003 % Get file names for specified directory 0004 % with specified basename and extension 0005 % --- Usage 0006 % [pathname, filename] = vb_get_session_filename(datadir,basename,ext) 0007 % [pathname, filename] = ... 0008 % vb_get_session_filename(datadir,basename,ext,session,mode) 0009 % --- Input 0010 % datadir : data directory name 0011 % ex. 'D:/data/eeg' 0012 % basename : file basename 0013 % ex. 'SK' , '' 0014 % ext : file extension 0015 % ex. '.bdf' 0016 % --- Optional Input 0017 % session : session number list 0018 % if session is given, filename is generated 0019 % by using [datadir, basename, ext, session] 0020 % mode : file name generation mode 0021 % --- Output 0022 % pathname : cell array of path for multiple files 0023 % pathname{n} = [datadir '/' filename{n} ext]; 0024 % filename : cell array of multiple file names without extension 'ext' 0025 % if session is given 0026 % filename{n} = [basename, sprintf('_%d', session(n))]; for mode=0 0027 % filename{n} = [basename, sprintf('_%02d',session(n))]; for mode=1 0028 % 0029 % Masa-aki Sato 2008-08-14 0030 % 0031 % Copyright (C) 2011, ATR All Rights Reserved. 0032 % License : New BSD License(see VBMEG_LICENSE.txt) 0033 0034 if nargin < 3, error('Input arguments should be more than 3'); end; 0035 if ~exist('session','var'), session = []; end; 0036 if ~exist('mode','var'),mode=0;end 0037 0038 if isempty(session) 0039 dlist = dir([datadir '/' basename '*' ext]); 0040 Nfile = length(dlist); 0041 0042 pathname = cell(1,Nfile); 0043 filename = cell(1,Nfile); 0044 0045 for n=1:Nfile 0046 fname = dlist(n).name; 0047 y = findstr(fname,ext); 0048 filename{n} = fname(1:y(1)-1); 0049 0050 pathname{n} = [datadir '/' fname]; 0051 end 0052 0053 return 0054 end 0055 0056 Nsession = length(session); 0057 0058 pathname = cell(1,Nsession); 0059 filename = cell(1,Nsession); 0060 0061 for n=1:Nsession 0062 if mode==0 0063 filename{n} = [basename, sprintf('_%d',session(n))]; 0064 else 0065 filename{n} = [basename, sprintf('_%02d',session(n))]; 0066 end 0067 0068 if isempty(datadir) 0069 pathname{n} = [filename{n} ext]; 0070 else 0071 pathname{n} = [datadir '/' filename{n} ext]; 0072 end 0073 end 0074 0075 return