i've wanted to know how to get the directory of a program using the app.path command ... how would i go about it?
Printable View
i've wanted to know how to get the directory of a program using the app.path command ... how would i go about it?
Dim AppPath$
If Right(App.Path, 1) <> "\" Then _
AppPath = App.Path & "\" _
Else AppPath = App.Path
End If
use this when you store all your app files in one dir
then when calling a file you simpley say
Open AppPath & Myfile.txt for append as # 1
that way..if the folder is stored on another pc
under D:\yourstuff\mystuff\xyz
the application will find it cause it looks for
myfile.txt in the app path which is the path where
the folder is stored..
Yea...hopefully I haven't confused you to death..
u lost me after dim apppath$
If by "directory of a program" you mean the folder where the program is installed, then assuming that the program is installed in c:\xyz then
MsgBox App.Path & "\" & "myfile.txt" would display
c:\xyz\myfile.txt
HeSaidJoe had a few extra lines in his code to make sure if the app is in the root folder, it wouldn't return "C:\\" instead of "C:\"
It's safer that way.
i just want to know the directory of where the user might have put my program in ... lets say "c:\xyz\prog.exe"
that way when i get the directory then i could tell my program to play a music file that came with the program which should be in the same directory n if not then don't play it ...
If you write and app and don't use app.path
and for arguments sake we store your files
in c:\yourfolder
We then take your app and install it on my pc
but on my pc I put your app in D:\myfolder
When I go to run your app I will get errors
on file not found because the path's will be
different even though the file names are the
same.
If you use app.path then app.path is the path
the app is stored in so regardless of where it
is stored it will look for yourfile.txt and
find it as long as it is stored in the folder
where your app is stored.
When I dim AppPath I am just creating
an instance of App.Path and if the App.Path
doesn't have a \ on the end of it I am putting
one there. I then use AppPath instead of App.Path
Just habit..you could just as easily just add
the \ to the end of App.Path if it wasn't there
That is the best I can do at explaining the function
App.Path