Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Directory vs. "My" Directory

Status
Not open for further replies.

NetNomad312

Technical User
Jun 16, 2004
27
US
I didn't want to bring this one here because I thought it was so simple... and at one point I thought I found the solution.

My original problem was: my program would always save its INI in C:\, because I copied my method of "checking if the INI exists and if not create it" from a tutorial that I have since lost the address of. It basically consisted of defining "temp$", setting it to Dir([full file path]), and then, "If temp$ <> [filename] Then (create it)". But I recently redesigned the program to be a bit easier to use, and I plan to give this version to more people. So an INI that's permenantly stuck in C:\ is not really an option anymore.

Looking through the MSDN library for something I could use, I came across "CurDir." I thought this is what I needed, and rewrote the code this way:

Code:
Dim fso As New FileSystemObject

If fso.FileExists("Config.ini") = False Then
     (create new ini, etc.)
     MsgBox (message here saying new ini was created)
Else
     lpFileName = CurDir + "\Config.ini"
     (load data from INI)
End if

Turns out CurDir isn't what I thought it was. It seems to change whenever I used one of the browse boxes in my program... and then the next time I run the program it keeps telling me it created a new INI. I'm guessing "CurDir" refers to the directory Windows is currently looking at as opposed to the directory my program is in, is that right?

I guess it's possible to use "File" objects to do some of this... maybe. I dunno. As you've probably figured out by now, I know very little about this. I was never taught anything about working with files in the single class I once took that used VB6 (which was a highschool class), and so far I've never used the FileSystemObject in my program; I've been using some functions that I copied from that tutorial that I forgot the name of... functions that use kernel32 to read from and write to INI files somehow. This is all I really know, and I'm trying to figure out the rest of it as I go (which is why I regret having to bring such a dumb question here). What I can't figure out is, how do I get it to say "my directory" + [filename]?
 

Use the directory in App.Path instead, then your INI will always be in the directory with the EXE.
 
...see, this is the kind of thing that ought to just smack me in the face, but I just miss it. Thanks a lot. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top