Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set default working folder to the application folder

Posted on 2003-11-11
5
Medium Priority
?
335 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

926 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