-1

I need to find the path to the user's vlc.exe file. How can I do this?

I read this http://docs.oracle.com/javase/tutorial/essential/io/find.html and tried using code like

            PathMatcher match = FileSystems.getDefault().getPathMatcher("glob:vjlc.{exe, jpg, png}");

        Path filename = FileSystems.getDefault().getPath("vjlc.exe","");

        if(match.matches(filename))
        {
            System.out.println(filename);
        }

and

        File fil = new File("vlc.exe");
    System.out.println( fil.getAbsolutePath() );

neither of which worked

user1021085
  • 729
  • 3
  • 10
  • 28
  • Where is your code? What hv you done? – Shashank Kadne Feb 11 '12 at 13:10
  • 1
    Did you realise that you are trying to find "vjlc.exe" (notice extra 'j') path in the first code sample? – Korhan Ozturk Feb 11 '12 at 13:16
  • *"need to find the path to the user's vlc.exe file"* 1) Why? 2) What if the user does not have VLC installed? – Andrew Thompson Feb 11 '12 at 13:19
  • I added the j just to test something. Andrew, Because I need to know where the vlc.exe is so I can start it with options through the java program – user1021085 Feb 11 '12 at 13:27
  • Looks like you are trying to find where the VLC player is installed. In this case, you have to find out first where it is installed, for example by querying the Windows registry. – belgther Feb 11 '12 at 13:43
  • *"I can start it with options"* 1) When in doubt, be explicit. i.e. ***What options?*** 2) What is the answer to the 2nd question in my first comment? Getting information from you is like pulling teeth. 3) Note that I do not get notified of a comment reply unless you start the comment with something like @Andrew. I just happened to come back and check this thread. – Andrew Thompson Feb 11 '12 at 13:44

4 Answers4

1

I believe you are trying to do something that is not quite right.

First, you're assuming that vlc.exe exists on the local machine. But what happens if it doesn't?

Second, what happens if VLC decides at some point (new build comes out, or upgrade) to change the exe file name to vlc2.exe?

To deal with this kind of dependency, I suggest you'll pass the vlc file location as a program argument to the main() method. This way, you can create a batch file that tries to locate the vlc.exe path, and pass it through to the java program.

Another alternative, is to setup an environment variable, that will be set up during the installation of your java application. The installation can search for vlc.exe path, or have the user to set it up. Once the variable is set, the java program can read it from the system arguments (see this example).

A third way is to have a setting files (*.ini like), that will contain the vlc exe path. You can then have the file modified according to the relevant path, and have the java program read from it (as property file). The file can be auto generated too, during the installation process, or manually edited post installation.

Elad Tabak
  • 2,317
  • 4
  • 23
  • 33
0

You can use getAbsolutePath() function.

Korhan Ozturk
  • 11,148
  • 6
  • 36
  • 49
  • I have tried that. It didn't work. The output was C:\WorkStation\Souptest\vlc.exe which is wrong, that's just the project folder and it added a 'vlc.exe' at the end. – user1021085 Feb 11 '12 at 13:10
0

I think you're looking for ways of searching for the vlc.exe executable on the PATH. If so, something like the following should help:

String path = System.getenv("PATH");
String pathSeparator = System.getProperty("path.separator");

for (String pathElement : path.split(pathSeparator)) {
    File file = new File(pathElement, "vlc.exe");
    if (file.isFile()) {
        // vlc.exe exists in this location.
    }
}
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
0

When a user runs VLC installer to install VLC media player under Windows, the installer creates a Windows registry key entry HKLM\SOFTWARE\VideoLAN\VLC\InstallDir. You can retrieve the path stored in the key using Java as follows:

http://www.davidc.net/programming/java/reading-windows-registry-java-without-jni

read/write to Windows Registry using Java

If the HKLM\SOFTWARE\VideoLAN\VLC\InstallDir key is present, you know VLC is installed. If the user decides to install VLC at a different directory than what is suggested by VLC installer as default, the key will be able to tell you that.

This only works when the user installs VLC through its installer. But, it won't work if the user simply extracts VLC from its zip distribution file since this approach won't touch the Windows registry.

Community
  • 1
  • 1
ecle
  • 3,952
  • 1
  • 18
  • 22