On Sat, 27 Sep 2003, Helen Bennett wrote: > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] > > Behalf Of Dax T. Games > > Sent: 27 September 2003 22:10 > > To: [EMAIL PROTECTED] > > Subject: 'which' functionality in Perl > > > > How would I determine if a file existed in a directory > > in the PATH environment variable on a Windows box with > > Perl. If the file exists I want to return the full path > > to the file. > > > There is probably a module somewhere that does it.. but > the following function works as well .. may need to clean > up the items returned from path as they may have "\" on > the end, butt still works. > > Helen > > sub which ( $ ) > { > my ( $file ) = @_ ; > $path = $ENV{"PATH"} ; > foreach $dir (split (/;/, $path)) > { > return "$dir\\$file" if ( -e "$dir/$file" ) ; > } > return "not found" ; > } > print which ("cmd.exe") ;
There's also a module, File::Which, which supplies a script 'pwhich' which works much like the unix 'which'. A nice feature of this module is that it'll take into account the Win32 PATHEXT environment variable, if present, so you can say, for example, C:\> pwhich cmd and it'll return \path\to\cmd.exe. -- best regards, randy kobes _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs