igetdir_jd

PURPOSE ^

SYNOPSIS ^

function [selectpath] = igetdir_jd(opt_gui,message,presel);

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [selectpath] = igetdir_jd(opt_gui,message,presel);
0002 %
0003 if opt_gui == 1,
0004     %
0005     selectpath = uigetdir(presel,message);
0006     selectpath = [selectpath,'/'];
0007     %
0008 else
0009     %
0010     if ~isempty(presel),
0011         %
0012         if exist(presel,'dir'),
0013             pathname = presel;
0014             if pathname(end) ~= filesep,
0015                 pathname = [pathname,filesep];
0016             end
0017         else
0018             %
0019             disp(['WARNING : the directory ''',pathname,''' does not exist.'])
0020             %
0021             pathname = [pwd,'/'];
0022             %
0023         end
0024         %
0025     else
0026         pathname = [pwd,'/'];
0027     end
0028     %
0029     selectpath = '';
0030     %
0031     while isempty(selectpath);
0032         disp(' ');
0033         %
0034         disp(message);
0035         %
0036         files = dir(pathname);
0037         %
0038         isel = 0;
0039         select = {};
0040         %
0041         for ifile = 1:length(files),
0042             if files(ifile).isdir == 1 & ~strcmp(files(ifile).name,'CVS'),
0043                 %
0044                 select = [select,files(ifile).name];
0045                 %
0046                 if strcmp(files(ifile).name,'.'),
0047                     isel_loc = length(select);
0048                 elseif strcmp(files(ifile).name,'..'),
0049                     isel_back = length(select);
0050                 end
0051                 %
0052             end
0053         end
0054         %
0055         select_tmp = select;
0056         select_tmp([isel_loc,isel_back]) = [];
0057         select = [select([isel_loc,isel_back]),select_tmp];
0058         isel_loc = 1;
0059         isel_back = 2;
0060         %
0061         disp(' ');
0062         %
0063         disp(['-----> Select a subdirectory in the directory ''',pathname,''' :']);
0064         %
0065         disp(' ');
0066         %
0067         for ifile = 1:length(select),
0068             disp(['[',num2str(ifile),'] : ',select{ifile}])
0069         end
0070         %
0071         disp(' ');
0072         disp('[0] Create directory');
0073         disp(' ');
0074         disp('[-1] Cancel');
0075         disp(' ');
0076         disp('[-2] Current directory');
0077         disp(' ');
0078         %
0079         isel_new = input(['? [',num2str(isel_loc),'] : ']);
0080         %
0081         if isempty(isel_new),
0082             isel_new = isel_loc;
0083         end
0084         %
0085         if isel_new == -2,%current directory
0086             %
0087             selectpath = [pwd,'/'];
0088             %
0089         elseif isel_new == -1,%cancel operation
0090             %
0091             selectpath = 0;
0092             %
0093         elseif isel_new == 0,%create directory
0094             %
0095             newdirname = input('-----> Name of new directory : ','s');
0096             %
0097             if ~isempty(newdirname),
0098                 %
0099                 mkdir([pathname,newdirname])%
0100                 pathname = [pathname,newdirname,'/'];
0101             end
0102             %
0103         elseif isel_new == isel_back,%back one directory
0104             %
0105             pathname = pathname(1:max([1,find(pathname(1:end-1) == '/')]));
0106             %
0107         elseif isel_new == isel_loc,%this directory
0108             %
0109             selectpath = pathname;
0110             %
0111         else
0112             if isnumeric(isel) & length(isel) == 1 & any(isel_new == 1:length(select));
0113                 %
0114                 pathname = [pathname,select{isel_new},'/'];
0115                 %
0116             else
0117                 disp(['-----> Invalid option']);
0118             end
0119         end
0120         %
0121     end
0122 end
0123

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.