You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

1

Friday, January 21st 2011, 10:58am

App.Path -- again!!

I know ... this has been discussed many times!

Still, since the other solutions did not work for me and my App needs the path to its actual location to access other files I came up with this:

Source code

1
2
Dim MyAppPath as String
MyAppPath = Replace(Replace(Left(getClass().getProtectionDomain().getCodeSource().getLocation(),InStrRev(getClass().getProtectionDomain().getCodeSource().getLocation(), "/")),IIF(Left(Mid(getClass().getProtectionDomain().getCodeSource().getLocation(),8),1)=":","file:/","file:"),""),"%20"," ")


It works quite reliable on Mac and PC as long as your App is compiled to a .jar
Compiled to .exe it throws you the temp directory!

compiled runtime only!!

This post has been edited 1 times, last edit by "Dani" (Jan 21st 2011, 1:28pm)


A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Friday, January 21st 2011, 2:43pm

Thanks for your inspiration!

The following might be a bit simpler.
Haven't tested in on a Mac, though.

Jabaco Source

1
2
3
4
5
6
7
Public Function myAppPath2() As String
   Dim location As String = getClass().getProtectionDomain().getCodeSource().getLocation().getPath()

   location = Replace(location,"%20"," ")
    
   myAppPath2 = Mid(location, 2, Len(location) - 2)   ' remove leading and trailing slashes
End Function


Greetings

A1880

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Friday, January 21st 2011, 5:14pm

Hmm...
thanks for your reply. When I use Your function I get something like this though:

Quoted

C:/Dokumente und Einstellungen/xy/Eigene Dateien/Jabaco/App Path Test/AppPathTest.ja

Mac:

Users/xy/Desktop/AppPathTest.ja
What I was looking for was the path only with the trailing backslash:

Quoted

C:/Dokumente und Einstellungen/xy/Eigene Dateien/Jabaco/App Path Test/

Mac:

/Users/xy/Desktop/
On the Mac all you need to do really is to replace the '%' and strip the file name!!
So I needed something to figure out whether I am on a Mac or a PC. Thats why the 'file:' and not the '.getPath()'

Dani

Rate this thread
WoltLab Burning Board