V_UNIXWHICH Search system path for an executable program [F]=(C,E) Inputs: C name of file to search for (excluding extension) E list of extensions [default = '.com;.exe;.bat' unless C contains '.'] Outputs: F Full pathname of executable (use FILEPARTS() to split up) Notes: (1) This is WINDOWS specific and needs to be fixed to work on UNIX systems (2) The search is case insensitive (like most of WINDOWS). (3) The routine does not cache the directory listings so you should avoid doing the same search many times if you care about speed. (4) To include all files that CMD.EXE will search, set e=v_winenvar('pathext') (5) As well as their normal full-length name, WINDOWS files and folders have a short name assigned by the operating system that is 8 characters long (+ 3 more for the extension). These short names are usually hidden from the user and UNIXWHICH, unlike the operating system, will not search for them.
0001 function f=v_unixwhich(c,e) 0002 %V_UNIXWHICH Search system path for an executable program [F]=(C,E) 0003 % 0004 % Inputs: C name of file to search for (excluding extension) 0005 % E list of extensions [default = '.com;.exe;.bat' unless C contains '.'] 0006 % 0007 % Outputs: F Full pathname of executable (use FILEPARTS() to split up) 0008 % 0009 % Notes: (1) This is WINDOWS specific and needs to be fixed to work on UNIX systems 0010 % (2) The search is case insensitive (like most of WINDOWS). 0011 % (3) The routine does not cache the directory listings so you 0012 % should avoid doing the same search many times if you care 0013 % about speed. 0014 % (4) To include all files that CMD.EXE will search, set e=v_winenvar('pathext') 0015 % (5) As well as their normal full-length name, WINDOWS files and folders have 0016 % a short name assigned by the operating system that is 8 characters long 0017 % (+ 3 more for the extension). These short names are usually hidden from the 0018 % user and UNIXWHICH, unlike the operating system, will not search for them. 0019 0020 % Copyright (c) 2005 Mike Brookes, mike.brookes@ic.ac.uk 0021 % Version: $Id: v_unixwhich.m 10865 2018-09-21 17:22:45Z dmb $ 0022 % 0023 % VOICEBOX is a MATLAB toolbox for speech processing. 0024 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html 0025 % 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 % This program is free software; you can redistribute it and/or modify 0028 % it under the terms of the GNU General Public License as published by 0029 % the Free Software Foundation; either version 2 of the License, or 0030 % (at your option) any later version. 0031 % 0032 % This program is distributed in the hope that it will be useful, 0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0035 % GNU General Public License for more details. 0036 % 0037 % You can obtain a copy of the GNU General Public License from 0038 % http://www.gnu.org/copyleft/gpl.html or by writing to 0039 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0041 if nargin<2 0042 if any(c=='.') 0043 e=[]; 0044 else 0045 e='.com;.exe;.bat'; 0046 end 0047 end 0048 ei=[0 find(e==';') length(e)+1]; 0049 [v,pth]=system('path'); 0050 while pth(end)<=' ' 0051 pth(end)=[]; % remove junk from end 0052 end 0053 lpth=length(pth); 0054 sc=[0 find(pth==';') lpth+1]; 0055 f=[]; % initialize to null string = not found 0056 for i=2:length(sc) 0057 hd=pth(sc(i-1)+1:sc(i)-1); 0058 if length(hd) 0059 [v,fl]=system(['dir /B "',hd,'"']); 0060 fi=[0 find(fl==10)]; % split into individual file names using LF character 0061 for j=2:length(fi) 0062 fn=fl(fi(j-1)+1:fi(j)-1); 0063 for k=2:length(ei) 0064 ma=strcmpi(fn,[c e(ei(k-1)+1:ei(k)-1)]); 0065 if ma 0066 f=fullfile(hd,fn); 0067 return; 0068 end 0069 end 0070 end 0071 end 0072 end