If the application is on the same drive as the other application that will be fired, you can identify the drive of your application and then form the complete path of the second application.
For example, instead of fixing that other application (in my example, applitivo2.exe) is in D: Location of the application file2.exe, fix only your path relative to the root drive and create the full path from the root drive of the application that will run it:
String caminhoApp = System.getProperty("user.dir");
String unidadeApp = caminhoApp.substring(0, caminhoApp.indexOf(File.separator));
System.out.println(unidadeApp);
String nomeOutroApp = String.format("Local do arq%saplicativo2.exe", File.separator);
String caminhoOutroApp = new File(unidadeApp ,nomeOutroApp).getPath();
System.out.println(caminhoOutroApp);
If you do not know on which drive the other application will be on, you can do a search for drives. For example:
public String localizaOutroApp(String caminhoRelativoARaiz) {
File[] unidades = File.listRoots();
for(int i = 0; i < unidades.length ; i++) {
File arquivo = new File(unidades[i], caminhoRelativoARaiz);
if (arquivo.exists()) {
return arquivo.getPath();
}
}
return null;
}
Passing to the above function the path of the other application relative to the root, it will return the complete path of the other application no matter on which drive it has been found. Example:
// se o existe "F:\Local do arquivo\aplicativo2.exe", é este caminho que será impresso.
System.out.println(localizaOutroApp("Local do arquivo\\aplicativo2.exe"));
In the second example I used " instead of "File.separator" to make it easier to read. Always use "File.separator" if you want portability between operating systems.
Rodrigo, in case I would have to create a string in the property of my application, the codes posted is in Vb? because I’m creating an application in Vb, if it’s not too much you can give a summary of how to do this ae? because I’m new in visual basic and I’m taking this will be my work worth note.
– Douglas
@Douglas The code is in Java because this is the tag you used in your question. Dude, it’s been 15 years since I programmed in VB, I’m not going to venture so now :-) Or would it be VB.Net? Or VBA? I also didn’t understand "create a string in my application property". Correct the tags of your question and try to put more details such as what you have tried so far or how your code is currently.
– Caffé
sorry, I embarrassed myself in the tags, but thanks guy you may not have taken my doubt but maybe I took another with the same doubt, Fight even for having lost your time answering my doubt :D I will try again by putting tag VB.net
– Douglas
@Douglas Now you have put "VBA". It is VBA or VB.NET after all?
– Caffé
VBA visual basic
– Douglas