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

vb_get_multi_filename

PURPOSE ^

Get file names for specified directory and search string

SYNOPSIS ^

function [pathname, filename] =vb_get_multi_filename(datadir,searchkey,session_no)

DESCRIPTION ^

 Get file names for specified directory and search string
 --- Usage
  [pathname, filename] = vb_get_multi_filename(datadir,searchkey,session_no)
 --- Input
 datadir : data directory name
    ex.    'D:/data/eeg'
 searchkey : file search string
    ex.    '*_low_epoch.eeg.mat'
 --- Optional Input
 session_no : session number list 
 --- Output
 pathname : cell array of path for multiple files
   pathname{n} : n-th eeg file path
 filename : cell array of multiple eeg data file names
   filename{n} : n-th eeg file name

 Masa-aki Sato 2008-08-14

 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:

SOURCE CODE ^

0001 function    [pathname, filename] = ...
0002             vb_get_multi_filename(datadir,searchkey,session_no)
0003 % Get file names for specified directory and search string
0004 % --- Usage
0005 %  [pathname, filename] = vb_get_multi_filename(datadir,searchkey,session_no)
0006 % --- Input
0007 % datadir : data directory name
0008 %    ex.    'D:/data/eeg'
0009 % searchkey : file search string
0010 %    ex.    '*_low_epoch.eeg.mat'
0011 % --- Optional Input
0012 % session_no : session number list
0013 % --- Output
0014 % pathname : cell array of path for multiple files
0015 %   pathname{n} : n-th eeg file path
0016 % filename : cell array of multiple eeg data file names
0017 %   filename{n} : n-th eeg file name
0018 %
0019 % Masa-aki Sato 2008-08-14
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 dlist = dir([datadir '/' searchkey]);
0025 
0026 Nfile = length(dlist);
0027 
0028 if exist('session_no','var') && ~isempty(session_no)
0029     if max(session_no) > Nfile
0030         error('session number is larger than file number');
0031     end
0032 else
0033     session_no = 1:Nfile;
0034 end
0035 
0036 Nsession = length(session_no);
0037 pathname = cell(1,Nsession);
0038 filename = cell(1,Nsession);
0039 
0040 for n=1:Nsession
0041     filename{n} = dlist(session_no(n)).name;
0042     pathname{n} = [datadir '/' filename{n}];
0043 end

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