Solved

Set default working folder to the application folder

Posted on 2003-11-11
5
328 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

685 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