• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:


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?
1 Solution
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.



You might want to try the windir environment string.

Go to msdn.microsoft.com (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.
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Use GetWindowsDirectory API
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.)
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
oteAuthor Commented:
Thanks for the answer.
I think the "dirwalk" must be the best solution.
The problem is that I cannot find it in the "msdn.microsoft.com"
I use the "search msdn" option looking for Dirwalk but nothing is founded.
Could I have your  help please?
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.

oteAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now