Java File Attribute makeCurrentDirectoryThatOfExecutable(String executable)

Here you can find the source of makeCurrentDirectoryThatOfExecutable(String executable)

Description

Set the directory to that of the executable, such that "c:\some\dir\file.exe" will set to "c:\some\dir\"

License

GNU General Public License

Parameter

Parameter Description
executable fullpath executable, as in "c:\some\dir\file.exe" and not just "file.exe"

Return

previous directory

Declaration

public static String makeCurrentDirectoryThatOfExecutable(String executable) 

Method Source Code

//package com.java2s;
/** This class is a PanelLeft factory, creating all panels based on the
 * contents of the panels.xml file./* ww w  .j  av a 2s.c o m*/
 *
 * Last Updated:  May 25, 2011
 *
 * by Rick C. Hodgin
 * Cossatot Analytics Laboratories, LLC. (Cana Labs)
 *
 * (c) Copyright Cana Labs.
 * Free software licensed under the GNU GPL2.
 *
 * @author Rick C. Hodgin
 * @version 1.0.0
 *
 * Change history:
 *   2011-05-25 - 1.0.0 - Initial release
 *
 */

import java.io.File;

public class Main {
    /**
     * Set the directory to that of the executable, such that "c:\some\dir\file.exe"
     * will set to "c:\some\dir\"
     * @param executable fullpath executable, as in "c:\some\dir\file.exe" and
     * not just "file.exe"
     * @return previous directory
     */
    public static String makeCurrentDirectoryThatOfExecutable(String executable) {
        String curDir, newDir;

        curDir = getCurrentDirectory();
        newDir = new File(executable).getParent();
        setCurrentDirectory(newDir);

        return (curDir);
    }

    public static String getCurrentDirectory() {
        return (System.getProperty("user.dir"));
    }

    public static void setCurrentDirectory(String dir) {
        System.setProperty("user.dir", dir);
    }
}

Related

  1. findJavaCompilerExecutableInDir(File dir)
  2. findJavaExecutable(File vmInstallLocation)
  3. findUnixExecutable(String unixCommandLineExecutables)
  4. javaExecutable(File jre)
  5. launchExecutable(String executable, List args, Preferences preferences)
  6. makeExecutable(File file)
  7. makeExecutable(File file)
  8. makeExecutable(File file)
  9. makeExecutable(File file)