Solved

Set default working folder to the application folder

Posted on 2003-11-11
5
326 Views
Last Modified: 2010-05-01
Hi

When i'm deploying a program i need to read from a file. For some reason the default working directory is "c:\documents and settings\my name"
and not "My Documents" which is the users personal data folder in the deployment project.

How do i set the default working folder to be e.g. the application folder (where the .exe file resides) for the program. I can't set it hardcoded in the code coz i don't know the exact path on the target computer.

I'd rather not dump files in the documents and setting folders or especially the My Documents folder since then the files might accidently be deleted by user. I'd rather use the application folder.

Thanks

KjartanM-S
0
Comment
Question by:KjartanM-S
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:tim_mcgue
ID: 9726682
Have you tried:

CurDir

See this URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctcurdir.asp

If you are using vbscript instead of VB it is:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.CurrentDirectory 'this is the directory where the script was launched
0
 

Author Comment

by:KjartanM-S
ID: 9726779
HI

Sorry, my fault for not specifying properly. I'm developing in VB.NET and have used the getCurrentDirectory call there (equal to CurDir in VB i think). When program is deployed and running it returns the c:\Documents and Settings\KjartanM-S.

I'd rather it be something like
"c:\program files\my program"
where the .exe file is (or as the deployment calls it - application folder)
Problem is that i don't know the exact path on the target computer, depending on where he chooses to install the program.

I need to find the exact path of the application folder on once the program is deployed and running.

KjartanM-S
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9726789
Is there an app.path equivalent in .Net?

Dim myFile As String
If Right$(App.Path, 1) <> "\" Then
    myFile = App.Path & "\SomeFile.txt"
Else
    myFile = App.Path & "Somefile.txt"
End If

0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
ID: 9727064
0
 

Author Comment

by:KjartanM-S
ID: 9727134
vinnyd79

Thanks.....the link you provided answered my question about the startup path.

A note on my problem though.....following the instructions in a book on how to create a folder in your programs menu with link to program in the deployment project.....it actually said to included the .exe files in this folder which then created two instances of the .exe file. This one pointing to the documents and setting folder when using getCurrentDir.
Rather than including the .exe file one create a shortcut from the primary outputs in application folder and then copy this one to the programs menu folder. Then you get a proper shortcut here and the .exe file from the application folder is launched and getCurrentDir will return the same as application.startUpPath

KjartanM-S
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question