classdef ls_mod < handle
%
% LS_MOD shows directory listings. It is rather like the dir command in
% Windows or ls command in Unix.
%
% LS_MOD is a GUI-based program which allows you to perform different
% kinds of listings or searches.
%
% Define a path for directory listing (text field below the title Insert
% Path:). You can either manually define a path or just use the browse
% button. Press the execute button to start the listing (or search) and
% when you are done, close the gui by pressing the close button.
%
% In order to add a few rules for listing(or search), inside the preferences
% panel you are able to specify some options (see below).
%
% A List of GUI preferences:
% Show Hidden Files (checkbox, default off)
% List Subdirectories Recursively (checkbox, default off)
% Show Sizes (checkbox, default off)
% Show Last Modified Date (checkbox, default off)
% Search Field (text field, default none):
% Inside the text field (reads Type search text...) you can
% define words or parts of words you would like to be searched.
% When searching a particular file(s), you can define a search
% text in a form of str*, *str and str. Where str is a string
% which will be contained in a file's name.
% It's possible to use the wildcard character "*" at the end of a
% string or at the beginning of a string. If the asterisk operator
% is used at the end of string, a file name is assumed to start
% with a specified string. Consistently, if the asterisk operator
% is used at the beginning of a string, a file name is assumed
% to end with a specified string. On the other hand a mere string
% without the asterisk operator is searched throughout the file
% name. The search is done based on case-insensitivity.
% All the matched files will be highlighted in red.
% You can clear the text field by pressing the right-mouse button
% inside the field if there is a text Type search text...
% Order by name, last modified date or size (popupmenu, default name)
% Define file size for filtering(text field, default none):
% All the files less than a specified size will be filtered.
% You can reverse the filtering direction by changing the .LT. value
% to .GT.(popupmenu). In this case the program will filter all
% the files larger than a specified value.
% Define date for filtering (text field, default none):
% You can either specify the date manually or press the Select a
% single date button which opens the uicalendar tool. In case you
% prefer to give the date directly to the field the format must be
% dd.mm.yyyy. Like in the size filtering mode, you can also reverse
% the filtering direction by changing the .LT. value to .GT.
%
%
% See also: ls, dir
%
% Author: Mikko Leppnen 24/10/2011
%
% Version history:
% 23/09/2011 - first release
% 30/09/2011 - second release
% 11/10/2011 - third release
% 24/10/2011 - fourth release
properties(Access=private)
flags = zeros(6,1);
inputs;
dircount = 0;
filecount = 0;
totsize = 0;
filterSize = 0;
filterdate;
filterflags = zeros(2,1);
namefilter = {};
namefilterend = {};
namefilterstart = {};
data;
mainpath;
currentpath = '';
hMainFig;
hPathField;
hBrowseButton;
hExecuteButton;
hCloseButton;
hPrintPanel;
hOptionsPanel;
hPrintResBox;
hFilesFoundBox;
hOptsHiddenCB;
hOptsRecursiveCB;
hOptsSizeCB;
hOptsModifiedCB;
hSortList;
hFilterSizeField;
hFilterSizeDir;
hFilterNameField;
hSearchWordField;
hFileSizeList;
hFilterDateField;
hCalendarButton;
hFilterDateDir;
end
methods
function obj = ls_mod % class constructor
% parse inputs
clc;
createGUI(obj)
end
end
methods(Access=private)
function processlist(obj,files,dirs)
% process directories and files according to input options and
% print the results
printdata = {};
if ~isempty(dirs)
datesForDirs = {obj.data([obj.data.isdir]).datenum};
datesForDirs = datesForDirs(:);
if obj.flags(5) % order by last modified date
[val,ind1] = sort([obj.data([obj.data.isdir]).datenum],'descend');
dirs = dirs(ind1);
datesForDirs = datesForDirs(ind1);
end
if ~obj.flags(1) % show hidden option off
datesForDirs(~cellfun(@isempty,regexpi(dirs,'^\.','match'))) = [];
dirs(~cellfun(@isempty,regexpi(dirs,'^\.','match'))) = [];
else
datesForDirs(~cellfun(@isempty,regexpi(dirs,'^\.$|^\.\.$','match'))) = [];
dirs(~cellfun(@isempty,regexpi(dirs,'^\.$|^\.\.$','match'))) = [];
end
dirs = dirs(:);
printdata = cell(numel(dirs),1);
if (isempty(get(obj.hSearchWordField,'string')) ||...
strcmp(get(obj.hSearchWordField,'string'),'Type search text...'))
datesForDirs = cellfun(@datestr,datesForDirs,...
repmat({'dd-mmm-yyyy HH:MM:SS'},numel(datesForDirs),1),'uni',false);
for k = 1:numel(dirs)
if obj.flags(2)
printdata{k} = [sprintf('\t%-39s',datesForDirs{k}),sprintf('% s',dirs{k})];
else
printdata{k} = [sprintf('\t%-39s',''),sprintf('% s',dirs{k})];
end
end
end
end
if ~isempty(files)
datesForFiles = {obj.data(~[obj.data.isdir]).datenum};
bytesForFiles = {obj.data(~[obj.data.isdir]).bytes};
% order cell arrays columnwise to reduce search time
datesForFiles = datesForFiles(:);
bytesForFiles = bytesForFiles(:);
files = files(:);
if obj.flags(5) % order by last modified date
[val,ind2] = sort([obj.data(~[obj.data.isdir]).datenum],'descend');
files = files(ind2);
datesForFiles = datesForFiles(ind2);
bytesForFiles = bytesForFiles(ind2);
elseif obj.flags(6) % order by size
[bytesForFiles,ind3] = sort([obj.data(~[obj.data.isdir]).bytes],'descend');
if isa(bytesForFiles,'double')
bytesForFiles = num2cell(bytesForFiles);
end
files = files(ind3);
datesForFiles = datesForFiles(ind3);
end
if ~obj.flags(1) % show hidden option off
datesForFiles(~cellfun(@isempty,regexpi(files,'^\.','match'))) = [];
bytesForFiles(~cellfun(@isempty,regexpi(files,'^\.','match'))) = [];
files = files(cellfun(@isempty,regexpi(files,'^\.','match')));
end
inds = [];
if ~isempty(obj.namefilterend)
for k = 1:numel(obj.namefilterend)
inds = [inds;find(~cellfun(@isempty,regexpi(files,...
['[\w-~\.]*',regexprep(obj.namefilterend{k},...
'\.','\\\.'),'$'],'match')))];
end
end
if ~isempty(obj.namefilterstart)
for k = 1:numel(obj.namefilterstart)
inds = [inds;find(~cellfun(@isempty,regexpi(files,...
['^',regexprep(obj.namefilterstart{k},...
'\.','\\\.'),'[\w-~\.]*'],'match')))];
end
end
if ~isempty(obj.namefilter)
for k = 1:numel(obj.namefilter)
inds = [inds;find(~cellfun(@isempty,regexpi(files,...
['[\w-~\.]*',regexprep(obj.namefilter{k},...
'\.','\\\.'),'[\w\-\~\.]*'],'match')))];
end
end
if ~isempty(get(obj.hSearchWordField,'string')) &&...
~strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
inds = unique(inds);
files = files(inds);
datesForFiles = datesForFiles(inds);
bytesForFiles = bytesForFiles(inds);
end
printdata = [printdata;cell(numel(files),1)];
if ~isempty(files)
datesForFiles = cellfun(@datestr,datesForFiles,...
repmat({'dd-mmm-yyyy HH:MM:SS'},numel(datesForFiles),1),'uni',false);
for k = numel(dirs)+(1:numel(files))
if obj.flags(2) % show modified date
printdata{k} = sprintf('\t%-23s',datesForFiles{k-numel(dirs)});
else
printdata{k} = sprintf('\t%-23s',' ');
end
if obj.flags(4) % show sizes
printdata{k} = [printdata{k},sprintf('% 15s',num2str(bytesForFiles{k-numel(dirs)}))];
else
printdata{k} = [printdata{k},sprintf('% 15s','')];
end
printdata{k} = [printdata{k},sprintf(' % s',files{k-numel(dirs)})];
end
end
if obj.filterflags(1)
filInd = zeros(100,1);
sizefactor = 1e3;
switch get(obj.hFileSizeList,'value')
case 1
sizefactor = 1;
case 3
sizefactor = 1e6;
case 4
sizefactor = 1e9;
end
switch get(obj.hFilterSizeDir,'value')
case 1
for it = numel(dirs)+(1:numel(bytesForFiles))
if bytesForFiles{it-numel(dirs)} < obj.filterSize*sizefactor;
filInd(it-numel(dirs)) = it;
end
end
case 2
for it = numel(dirs)+(1:numel(bytesForFiles))
if bytesForFiles{it-numel(dirs)} > obj.filterSize*sizefactor;
filInd(it-numel(dirs)) = it;
end
end
end
if any(filInd)
printdata(filInd(filInd > 0)) = [];
files(filInd(filInd > 0)-numel(dirs)) = [];
bytesForFiles(filInd(filInd > 0)-numel(dirs)) = [];
datesForFiles(filInd(filInd > 0)-numel(dirs)) = [];
end
end
if obj.filterflags(2)
filIndF = zeros(100,1);
filIndD = zeros(100,1);
switch get(obj.hFilterDateDir,'value')
case 1
for it = 1:numel(dirs)
try
if datenum(datesForDirs{it},'dd-mmm-yyyy HH:MM:SS') <...
obj.filterdate
filIndD(it) = it;
end
catch ME
%warning(ME.identifier,ME.message)
end
end
if ~isempty(files)
for it = numel(dirs)+(1:numel(bytesForFiles))
try
if datenum(datesForFiles{it-numel(dirs)},'dd-mmm-yyyy HH:MM:SS') <...
obj.filterdate
filIndF(it-numel(dirs)) = it;
end
catch ME
%warning(ME.identifier,ME.message)
end
end
end
case 2
for it = 1:numel(dirs)
try
if datenum(datesForDirs{it},'dd-mmm-yyyy HH:MM:SS') >...
obj.filterdate
filIndD(it) = it;
end
catch ME
%warning(ME.identifier,ME.message)
end
end
if ~isempty(files)
for it = numel(dirs)+(1:numel(bytesForFiles))
try
if datenum(datesForFiles{it-numel(dirs)},'dd-mmm-yyyy HH:MM:SS') >...
obj.filterdate
filIndF(it-numel(dirs)) = it;
end
catch ME
%warning(ME.identifier,ME.message)
end
end
end
end
if any(filIndF) && ~any(filIndD)
printdata(filIndF(filIndF > 0)) = [];
files(filIndF(filIndF > 0)-numel(dirs)) = [];
bytesForFiles(filIndF(filIndF > 0)-numel(dirs)) = [];
elseif any(filIndD)
if any(filIndF)
printdata([filIndD(filIndD > 0);filIndF(filIndF > 0)]) = [];
files(filIndF(filIndF > 0)-numel(dirs)) = [];
bytesForFiles(filIndF(filIndF > 0)-numel(dirs)) = [];
else
printdata(filIndD(filIndD > 0)) = [];
end
dirs(filIndD(filIndD > 0)) = [];
end
end
end
obj.filecount = obj.filecount + numel(files); % count files
obj.dircount = obj.dircount + numel(dirs);
if exist('bytesForFiles','var')
obj.totsize = obj.totsize + sum(cell2mat(bytesForFiles)); % count sizes
end
if ~obj.flags(3)
fprintf('\n');
if ~isempty(get(obj.hSearchWordField,'string')) &&...
~strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
fprintf('\t%s:\n',get(obj.hPathField,'string'));
fprintf(2,'%s\n',printdata{numel(dirs)+(1:numel(files))});
fprintf('\n\t%d files, total %10G MB\n',obj.filecount, obj.totsize/1e6);
else
fprintf('%s\n',printdata{:});
fprintf('\n\t%d files, %d directory, total %10G MB\n',obj.filecount,obj.dircount,obj.totsize/1e6);
end
else
if ~isempty(get(obj.hSearchWordField,'string')) &&...
~strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
if ~isempty(files)
fprintf('\n\t%s:\n',obj.mainpath);
fprintf(2,'%s\n',printdata{numel(dirs)+(1:numel(files))});
end
else
fprintf('%s\n',printdata{:});
end
end
end
function recursivelisting(obj,dirs)
% list subdirectories recursively
obj.data = dir(dirs);
dirnames = {obj.data([obj.data.isdir]).name};
filenames = {obj.data(~[obj.data.isdir]).name};
obj.mainpath = dirs;
processlist(obj,filenames,dirnames)
if ~obj.flags(1)
dirnames(~cellfun(@isempty,regexpi(dirnames,'^\.','match'))) = [];
else
dirnames(~cellfun(@isempty,regexpi(dirnames,'^\.$|^\.\.$','match'))) = [];
end
for k = 1:numel(dirnames)
obj.mainpath = fullfile(dirs,dirnames{k});
if isempty(get(obj.hSearchWordField,'string')) ||...
strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
fprintf('\n\t%s:\n',fullfile(dirs,dirnames{k}))
recursivelisting(obj,fullfile(dirs,dirnames{k}))
else
recursivelisting(obj,fullfile(dirs,dirnames{k}))
end
end
end
function createGUI(obj)
screensize = get(0,'ScreenSize');
obj.hMainFig = figure('units','pixels',...
'pos',[screensize(1)*2,screensize(2)*25,...
screensize(3)*0.4,screensize(4)*0.25],...
'name','ls_mod',...
'numbertitle', 'off',...
'menubar','none',...
'visible','on',...
'toolbar','none',...
'tag','lsmodFig',...
'CreateFcn','movegui(''center'')',...
'DeleteFcn',@(varargin)figDeleteFcn(obj),...
'keypressfcn',@(varargin)figKeyCallback(obj,varargin),...
'color',[0.7137,0.7765,0.7843],...
'resize','off');
obj.hPathField = uicontrol('parent',obj.hMainFig,...
'style','edit',...
'tag','pathfield',...
'backgroundcolor','white',...
'units','normalized',...
'pos',[0.05 0.175 0.45 0.075],...
'visible','on',...
'string','',...
'tooltipstring','insert path',...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hBrowseButton = uicontrol('parent',obj.hMainFig,...
'style','push',...
'units','normalized',...
'userdata',1,...
'pos',[0.525 0.175 0.125 0.085],...
'backgroundcolor',get(gcf,'color'),...
'selectionhighlight','off',...
'enable','on',...
'tag','browsebutton',...
'string','Browse...',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)browseButtonCallback(obj));
uicontrol('parent',obj.hMainFig,...
'style','text',...
'string','Insert Path:',...
'units','normalized',...
'backgroundcolor',get(gcf,'color')',...
'pos',[0.05 0.25 0.3 0.075],...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hExecuteButton = uicontrol('parent',obj.hMainFig,...
'style','push',...
'units','normalized',...
'userdata',1,...
'pos',[0.05 0.05 0.1 0.085],...
'backgroundcolor',get(gcf,'color'),...
'selectionhighlight','off',...
'enable','on',...
'tag','executebutton',...
'string','Execute',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)executeButtonCallback(obj),...
'keypressfcn',@(varargin)figKeyCallback(obj,varargin));
obj.hCloseButton = uicontrol('parent',obj.hMainFig,...
'style','push',...
'units','normalized',...
'userdata',1,...
'pos',[0.85 0.05 0.1 0.085],...
'backgroundcolor',get(gcf,'color'),...
'selectionhighlight','off',...
'enable','on',...
'tag','executebutton',...
'string','Close',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)closeButtonCallback(obj));
obj.hOptionsPanel = uipanel('parent',obj.hMainFig,...
'units','normalized',...
'backgroundcolor',get(gcf,'color'),...
'pos',[0.05 0.35 0.9 0.6],...
'userdata','',...
'tag','optionspanel',...
'title','Preferences',...
'fontname','verdana',...
'fontsize',8,...
'foregroundcolor','b');
obj.hOptsHiddenCB = uicontrol('parent',obj.hOptionsPanel,...
'style','checkbox',...
'tag','optshiddencb',...
'backgroundcolor',get(gcf,'color'),...
'units','normalized',...
'pos',[0.025 0.85 0.4 0.09],...
'visible','on',...
'string','Show Hidden Files',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)optsHiddenCBCallback(obj));
obj.hOptsRecursiveCB = uicontrol('parent',obj.hOptionsPanel,...
'style','checkbox',...
'tag','optsrecursivecb',...
'backgroundcolor',get(gcf,'color'),...
'units','normalized',...
'pos',[0.025 0.65 0.4 0.1],...
'visible','on',...
'string','List Subdirectories Recursively',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)optsRecursiveCBCallback(obj));
obj.hOptsSizeCB = uicontrol('parent',obj.hOptionsPanel,...
'style','checkbox',...
'tag','optssizecb',...
'backgroundcolor',get(gcf,'color'),...
'units','normalized',...
'pos',[0.025 0.45 0.4 0.1],...
'visible','on',...
'string','Show Sizes',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)optsSizeCBCallback(obj));
obj.hOptsModifiedCB = uicontrol('parent',obj.hOptionsPanel,...
'style','checkbox',...
'tag','optsmodifiedcb',...
'backgroundcolor',get(gcf,'color'),...
'units','normalized',...
'pos',[0.025 0.25 0.4 0.1],...
'visible','on',...
'string','Show Last Modified Date',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)optsModifiedCBCallback(obj));
obj.hSearchWordField = uicontrol('parent',obj.hOptionsPanel,...
'style','edit',...
'tag','searchwordfield',...
'backgroundcolor','white',...
'units','normalized',...
'pos',[0.025 0.025 0.3 0.15],...
'visible','on',...
'string','Type search text...',...
'tooltipstring','',...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10,...
'ButtonDownFcn',@(varargin)searchWordFieldBdf(obj));
uicontrol('parent',obj.hOptionsPanel,...
'style','text',...
'string','Order by name, last modified date or size:',...
'units','normalized',...
'backgroundcolor',get(gcf,'color')',...
'pos',[0.45 0.85 0.5 0.1],...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hSortList = uicontrol('parent',obj.hOptionsPanel,...
'style','popupmenu',...
'units','normalized',...
'pos',[0.45 0.725 0.2 0.1],...
'enable','on',...
'string',{'Name','Modified','Size'},...
'callback',@(varargin)curveListFcn(obj,varargin),...
'tag','sortlist',...
'value',1,...
'userdata',1,...
'tag','filesizelist',...
'backgroundcolor','white',...
'callback',@(varargin)sortListCallback(obj),...
'fontname','verdana',...
'fontsize',10);
uicontrol('parent',obj.hOptionsPanel,...
'style','text',...
'string','Define file size for filtering:',...
'units','normalized',...
'backgroundcolor',get(gcf,'color')',...
'pos',[0.45 0.525 0.3 0.1],...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hFilterSizeField = uicontrol('parent',obj.hOptionsPanel,...
'style','edit',...
'tag','filtersizefield',...
'backgroundcolor','white',...
'units','normalized',...
'pos',[0.45 0.35 0.15 0.15],...
'visible','on',...
'string','',...
'tooltipstring','',...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hFileSizeList = uicontrol('parent',obj.hOptionsPanel,...
'style','popupmenu',...
'units','normalized',...
'pos',[0.61 0.35 0.075 0.15],...
'enable','on',...
'string',{'B','KB','MB','GB'},...
'value',2,...
'userdata',1,...
'tag','filesizelist',...
'backgroundcolor','white',...
'fontname','verdana',...
'fontsize',10);
obj.hFilterSizeDir = uicontrol('parent',obj.hOptionsPanel,...
'style','popupmenu',...
'units','normalized',...
'pos',[0.7 0.35 0.085 0.15],...
'enable','on',...
'string',{'.LT.','.GT.'},...
'tag','filtersizedir',...
'value',1,...
'userdata',1,...
'tag','filesizelist',...
'backgroundcolor','white',...
'fontname','verdana',...
'fontsize',10);
uicontrol('parent',obj.hOptionsPanel,...
'style','text',...
'string','Define date for filtering:',...
'units','normalized',...
'backgroundcolor',get(gcf,'color')',...
'pos',[0.45 0.2 0.3 0.125],...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hFilterDateField = uicontrol('parent',obj.hOptionsPanel,...
'style','edit',...
'tag','filterdatefield',...
'backgroundcolor','white',...
'units','normalized',...
'pos',[0.45 0.025 0.15 0.15],...
'visible','on',...
'string','',...
'tooltipstring','',...
'horizontalalignment','left',...
'fontname','verdana',...
'fontsize',10);
obj.hCalendarButton = uicontrol('parent',obj.hOptionsPanel,...
'style','push',...
'units','normalized',...
'userdata',1,...
'pos',[0.61 0.025 0.25 0.15],...
'backgroundcolor',get(gcf,'color'),...
'selectionhighlight','off',...
'enable','on',...
'tag','calendarbutton',...
'string','Select a single date',...
'fontname','verdana',...
'fontsize',10,...
'callback',@(varargin)calendarButtonCallback(obj));
obj.hFilterDateDir = uicontrol('parent',obj.hOptionsPanel,...
'style','popupmenu',...
'units','normalized',...
'pos',[0.87 0.025 0.085 0.15],...
'enable','on',...
'string',{'.LT.','.GT.'},...
'value',1,...
'userdata',1,...
'tag','filterdatedir',...
'backgroundcolor','white',...
'fontname','verdana',...
'fontsize',10);
end
%------------------------------------------------------------------
% Callback functions
%------------------------------------------------------------------
function browseButtonCallback(obj)
if isempty(obj.currentpath)
foldername = uigetdir();
else
foldername = uigetdir(obj.currentpath);
end
if isempty(foldername) || isequal(foldername,0)
return
end
set(obj.hPathField,'string',foldername);
obj.currentpath = foldername;
end
function figDeleteFcn(obj)
if isvalid(obj) && isobject(obj)
delete(obj)
end
end
function optsHiddenCBCallback(obj)
if get(obj.hOptsHiddenCB,'value') == 1
obj.flags(1) = 1;
else
obj.flags(1) = 0;
end
end
function optsRecursiveCBCallback(obj)
if get(obj.hOptsRecursiveCB,'value') == 1
obj.flags(3) = 1;
else
obj.flags(3) = 0;
end
end
function optsSizeCBCallback(obj)
if get(obj.hOptsSizeCB,'value') == 1
obj.flags(4) = 1;
else
obj.flags(4) = 0;
end
end
function optsModifiedCBCallback(obj)
if get(obj.hOptsModifiedCB,'value') == 1
obj.flags(2) = 1;
else
obj.flags(2) = 0;
end
end
function sortListCallback(obj)
if get(obj.hSortList,'value') == 2
obj.flags(5) = 1;
else
obj.flags(5) = 0;
end
if get(obj.hSortList,'value') == 3
obj.flags(6) = 1;
else
obj.flags(6) = 0;
end
end
function searchWordFieldBdf(obj)
if strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
set(obj.hSearchWordField,'string','');
end
end
function calendarButtonCallback(obj)
uicalendar('destinationui',obj.hFilterDateField,...
'weekend',[1 0 0 0 0 0 1],...
'selectiontype',1,...
'outputdateformat','dd.mm.yyyy');
end
function executeButtonCallback(obj)
if ~isempty(get(obj.hSearchWordField,'string')) &&...
~strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
expr_1 = '(?<=\*)[\w-~\.]*[\w-~]*';
expr_2 = '[\w-~\.]*(?=\*)';
obj.namefilterend = regexpi(get(obj.hSearchWordField,'string'),expr_1,'match');
obj.namefilterstart = regexpi(get(obj.hSearchWordField,'string'),expr_2,'match');
obj.namefilter = regexpi(regexprep(regexprep(regexprep(get(obj.hSearchWordField,'string'),...
'(?<=\*)[\w-~\.]*[\w-~]*',''),'[\w-~\.]*(?=\*)',''),...
'(\*)+',''),'[\w-~\.]*','match');
else
obj.namefilterend = {};
obj.namefilterstart = {};
obj.namefilter = {};
end
if ~isempty(get(obj.hFilterSizeField,'string'))
obj.filterflags(1) = 1;
if ~isempty(regexpi(get(obj.hFilterSizeField,'string'),'(\d+\.?\d*)','match'))
obj.filterSize = str2double(cell2mat(regexpi(get(obj.hFilterSizeField,'string'),...
'(\d+\.?\d*)','match')));
end
else
obj.filterSize = 0;
obj.filterflags(1) = 0;
end
if ~isempty(get(obj.hFilterDateField,'string'))
obj.filterflags(2) = 1;
if ~isempty(regexp(get(obj.hFilterDateField,'string'),'(\d){1,2}(\.){1}(\d){1,2}(\.){1}(\d){4}','match'))
try
obj.filterdate = datenum(regexp(get(obj.hFilterDateField,'string'),...
'(\d){1,2}(\.){1}(\d){1,2}(\.){1}(\d){4}','match'),'dd.mm.yyyy');
catch ME
warning(ME.identifier,ME.message)
warning('ignoring filtering date.')
end
end
else
obj.filterflags(2) = 0;
end
obj.data = dir(get(obj.hPathField,'string'));
if ~isempty(obj.data)
dirnames = {obj.data([obj.data.isdir]).name};
filenames = {obj.data(~[obj.data.isdir]).name};
if obj.flags(3)
fprintf('\n')
end
obj.mainpath = get(obj.hPathField,'string');
processlist(obj,filenames,dirnames)
if obj.flags(3) % recursive option on
if ~obj.flags(1)
dirnames(~cellfun(@isempty,regexpi(dirnames,'^\.','match'))) = [];
else
dirnames(~cellfun(@isempty,regexpi(dirnames,'^\.$|^\.\.$','match'))) = [];
end
for n = 1:numel(dirnames)
obj.mainpath = fullfile(get(obj.hPathField,'string'),dirnames{n});
if isempty(get(obj.hSearchWordField,'string')) ||...
strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
fprintf('\n\t%s:\n',fullfile(get(obj.hPathField,'string'),dirnames{n}))
recursivelisting(obj,fullfile(get(obj.hPathField,'string'),dirnames{n}))
else
recursivelisting(obj,fullfile(get(obj.hPathField,'string'),dirnames{n}))
end
end
if ~isempty(get(obj.hSearchWordField,'string')) &&...
~strcmp(get(obj.hSearchWordField,'string'),'Type search text...')
fprintf('\n\t%d files, total %10G MB\n',obj.filecount,obj.totsize/1e6);
else
fprintf('\n\t%d files, %d directory, total %10G MB\n',obj.filecount,obj.dircount,obj.totsize/1e6);
end
end
end
obj.dircount = 0;
obj.filecount = 0;
obj.totsize = 0;
fprintf('\n')
end
function figKeyCallback(obj,varargin)
key = varargin{1}(2);
if strcmp(key{1}.Key,'return')
executeButtonCallback(obj)
end
end
function closeButtonCallback(obj)
delete(gcbf)
end
end
end