Home > bml > io > bml_info_file.m

bml_info_file

PURPOSE ^

BML_INFO_FILE returns table with OS info of each file in a folder

SYNOPSIS ^

function info = bml_info_file(cfg)

DESCRIPTION ^

 BML_INFO_FILE returns table with OS info of each file in a folder

 Use as
   tab = bml_info_file(cfg);

 The first argument cfg is a configuration structure, which can contain
 the following field:
 cfg.path - string: path to the folder containing the files. Defauts to '.'
 cfg.pattern - string: file name pattern (eg '*.mat')
 cfg.regexp - string: regular expression to filter files
 cfg.filetype - string: variable added to info table

 Returns a matlab 'table' with the folloing variables:
   name - cell array of char: filename
   folder - cell array of char: path
   date - cell array of char: data of file modification 
   bytes - double: Size of the file in bytes
   isdir - logical: 1 if name is a folder; 0 if name is a file
   datenum - double: Modification date as serial date number.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function info = bml_info_file(cfg)
0002 
0003 % BML_INFO_FILE returns table with OS info of each file in a folder
0004 %
0005 % Use as
0006 %   tab = bml_info_file(cfg);
0007 %
0008 % The first argument cfg is a configuration structure, which can contain
0009 % the following field:
0010 % cfg.path - string: path to the folder containing the files. Defauts to '.'
0011 % cfg.pattern - string: file name pattern (eg '*.mat')
0012 % cfg.regexp - string: regular expression to filter files
0013 % cfg.filetype - string: variable added to info table
0014 %
0015 % Returns a matlab 'table' with the folloing variables:
0016 %   name - cell array of char: filename
0017 %   folder - cell array of char: path
0018 %   date - cell array of char: data of file modification
0019 %   bytes - double: Size of the file in bytes
0020 %   isdir - logical: 1 if name is a folder; 0 if name is a file
0021 %   datenum - double: Modification date as serial date number.
0022 
0023 path        = bml_getopt_single(cfg,'path','.');
0024 filepattern = bml_getopt_single(cfg,'pattern','*');
0025 fileregexp  = bml_getopt_single(cfg,'regexp',[]);
0026 
0027 filetype    = regexp(filepattern,'.*\.(.*)$','tokens','once');
0028 if isempty(filetype); filetype = 'unknown'; end
0029 filetype    = bml_getopt(cfg,'filetype',filetype);
0030 
0031 files=dir(fullfile(path, filepattern));
0032 if ~isempty(fileregexp)
0033   rx=regexp({files.name},fileregexp,'once');
0034   files=files(~cellfun(@isempty,rx));
0035 end
0036 
0037 if isempty(files)
0038   info=table();
0039 else
0040   if length(files)==1
0041     files.name = {files.name};
0042     files.folder = {files.folder};
0043     files.date = {files.date};
0044   end
0045   info=struct2table(files);
0046   info.filetype = repmat(filetype,height(info),1);
0047 end
0048

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005