Java File Find findExe(String exeName, String... path)

Here you can find the source of findExe(String exeName, String... path)

Description

Find the executable with the given name by checking the directories in the given path in order.

License

Open Source License

Parameter

Parameter Description
exeName an executable name (e.g., "mkfifo")
path a path (e.g., "/bin", "/usr/bin")

Exception

Parameter Description
DaemonException an exception

Return

full path to the executable, or null if the executable can't be found

Declaration

public static String findExe(String exeName, String... path) 

Method Source Code

//package com.java2s;
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

import java.io.File;

public class Main {
    /**//from  w w w .ja va  2  s .  c  o  m
     * Find the executable with the given name by checking the directories
     * in the given path in order.
     * 
     * @param exeName  an executable name (e.g., "mkfifo")
     * @param path     a path (e.g., "/bin", "/usr/bin")
     * @return full path to the executable, or null if the executable can't be found 
     * @throws DaemonException
     */
    public static String findExe(String exeName, String... path) {
        for (String dir : path) {
            File f = new File(dir + "/" + exeName);
            if (f.exists()) { // XXX: should check if it is executable
                return f.getPath();
            }
        }
        return null;
    }
}

Related

  1. find(String path, String suffix)
  2. find2(File baseDir, FileFilter filter, List files, boolean includeHiddenFiles)
  3. findByExt(File base, String ext)
  4. findByExtension(final File directory, final String extension)
  5. findByFileName(List files, String fileName)
  6. findExecutable(File baseLocation)
  7. findExecutable(String executableName)
  8. findExecutableInDirectory(String executable, File directory)
  9. findExecutableInPath(String exec)