Home > functions > common > utility > vb_get_ext_filename.m

vb_get_ext_filename

PURPOSE ^

Get file names for specified directory and extension

SYNOPSIS ^

function [pathname ,filename] = vb_get_ext_filename(datadir,ext)

DESCRIPTION ^

 Get file names for specified directory and extension
 --- Usage
  pathname = vb_get_ext_filename(datadir,ext)
 --- Input
 datadir : data directory name
    ex.    'D:/data/eeg'
 ext : file extension
    ex.    '_epoch.eeg.mat'
 --- Output
 pathname : pathname with specified extension
   if there are multiple files, pathname becomes cell array
   if there is no file, pathname is empty

 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] = vb_get_ext_filename(datadir,ext)
0002 % Get file names for specified directory and extension
0003 % --- Usage
0004 %  pathname = vb_get_ext_filename(datadir,ext)
0005 % --- Input
0006 % datadir : data directory name
0007 %    ex.    'D:/data/eeg'
0008 % ext : file extension
0009 %    ex.    '_epoch.eeg.mat'
0010 % --- Output
0011 % pathname : pathname with specified extension
0012 %   if there are multiple files, pathname becomes cell array
0013 %   if there is no file, pathname is empty
0014 %
0015 % Masa-aki Sato 2008-08-14
0016 %
0017 % Copyright (C) 2011, ATR All Rights Reserved.
0018 % License : New BSD License(see VBMEG_LICENSE.txt)
0019 
0020 dlist = dir([datadir '/*' ext]);
0021 Nfile = length(dlist);
0022 
0023 if Nfile==1,
0024     filename = dlist(1).name;
0025     pathname = [datadir '/' dlist(1).name];
0026 elseif Nfile > 1,
0027     filename = cell(1,Nfile);
0028     pathname = cell(1,Nfile);
0029 
0030     for n=1:Nfile
0031         filename{n} = dlist(n).name;
0032         pathname{n} = [datadir '/' dlist(n).name];
0033     end
0034 else
0035     filename = [];
0036     pathname = [];
0037 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005