4 import java.io.IOException;
7 * Miscellaneous file-related functions
9 public final class FileUtils
13 * Answers the executable file for the given command, or null if not found or
14 * not executable. The path to the executable is the command name prefixed by
15 * the given folder path, optionally with .exe appended.
18 * command short name, for example hmmbuild
20 * parent folder for the executable
23 public static File getExecutable(String cmd, String binaryPath)
25 File file = new File(binaryPath, cmd);
26 if (!file.canExecute())
28 file = new File(binaryPath, cmd + ".exe");
30 if (!file.canExecute())
40 * Answers the path to the folder containing the given executable file, by
41 * searching the PATH environment variable. Answers null if no such executable
47 public static String getPathTo(String cmd)
49 String paths = System.getenv("PATH");
50 // backslash is to escape regular expression argument
51 for (String path : paths.split("\\" + File.pathSeparator))
53 if (getExecutable(cmd, path) != null)
62 * A convenience method to create a temporary file that is deleted on exit of
70 public static File createTempFile(String prefix, String suffix)
73 File f = File.createTempFile(prefix, suffix);