Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 1999-08-01
Medium Priority
Last Modified: 2010-04-30
In a VB4 programm, as soon as the form is loaded, a small text-file named c.txt is been examined. The file has to be  in the windows directory and the path of the file is:
The code is:

FileNum = FreeFile
Open "c:\windows\c.txt" For Input As FileNum
Close FileNum

But suppose that a user has the Windows installed in another directory, (named win or wingk or something similar and NOT Windows), how could I be sure then that the file c.txt will be found (with the statement OPEN) and be opened?
Question by:ote
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1528816
I would by default set up your app to look in the default C:windows directory however when an error occures have the user set this path VIA the commondialog box and thensave this path to a text file locally. You will then just read from this file the path of the c.txt file.
Heres some snitptis of code that may or may not help. I am not sure if these work in VB4 as I am mostly familur with VB 5 & 6 so I am hesitent to place code for you but if you need more just ask and I will throw some in here for you.

Set Fso = CreateObject("scripting.fileSystemObject")
If Fso.FileExist("c:\windows\c.txt") = false then

   if fso.fileexist("c:\appSetUp.text") = false then
      FilePath = Commondialog1.Filename
      Write this path to a text file
      read from the c:\appsetup.text file the path to your c.txt file
   end if
end if

Hope I could be of some help for you.



LVL 25

Expert Comment

ID: 1528817
You might want to try the windir environment string.


Accepted Solution

vettranger earned 200 total points
ID: 1528818
Go to (no www. in front of this)

use the "search msdn" option

search for "Dirwalk"

You'll find a control that does exactly what you need. You'll need to be a registered VB user (or register when you go there), in order to download the control.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 15

Expert Comment

ID: 1528819
Use GetWindowsDirectory API

Expert Comment

ID: 1528820
With respect to the other commenters, just use the Dirwalk control as proposed. I used to do all this other stuff too, and none of it worked reliably or easily (you'd be surprised how many users can't find a file with the Open File dialog control ... or maybe you wouldn't! LOL)

The dirwalk control will just find the file anywhere on the drive, quickly and reliably, and you'll wind up using it in many circumstances ... its already found its way into most of my projects for various uses. (Like to find the location of MSACCESS.EXE, no matter where the user has installed it, when I need to shell to it as a runtime to display a report.)

Expert Comment

ID: 1528821
As an afterthought, another idea is to just keep your c.txt file in your application directory. You can ALWAYS easily find it then with :

f$=app.path & "\c.txt"
open f$ for input as #1

Author Comment

ID: 1528822
Thanks for the answer.
I think the "dirwalk" must be the best solution.
The problem is that I cannot find it in the ""
I use the "search msdn" option looking for Dirwalk but nothing is founded.
Could I have your  help please?

Expert Comment

ID: 1528823
Here's the URL (I was having trouble getting logged in to MSDN last night, or I would have included it then ... I was able to find it with the search but not get logged in to get to it. If you have any trouble getting to the URL, send me your Email address.

Author Comment

ID: 1528824
Thanks again.
I still have a probelm with the URL as I get the message:
"The file you requested could not be found"
My e-mail address is:

I really appreciate your help.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

688 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