I am trying to write a VB6 program to run from the Windows command line to look for certain files in the current command line directory and act on them.
I have tried no path, I have tried curdir, but I always get a file not found.
Is there a way to get a VB6 program to access a file based on the current windows command line directory?
Thanks!
Assuming the VB6 program is launched from within a Windows Cmd prompt, it will automatically use the directory from which it is launched as its current working directory, and will open files without a fully specified path in that directory. Note that this is the directory from which it is launched, not the directory in which the executable resides.
To test and demonstrate this, I created an extremely simple program. I started the VB6 IDE, and created the default project which opens with a single form Form1. On that form I placed a single button Command1, and within the _Click() event I placed the single line:
MsgBox "Current directory is: " & CurDir
Running this program from within the IDE produced the result
Current directory is: C:\Program Files\Microsoft Visual Studio\VB98
since that's where the IDE executable lives. however, compiling it and running the executable from a Cmd window -- or double-clicking on it in Explorer -- produced the expected result:
Current directory is: C:\Data
(I have my system set up uniquely, with my Documents directory pointed to C:\Data for historical reasons related to my workflow.) Running it from another directory also gave the expected result
C:\Data\Projects
even though the executable Project1.exe still resided in the C:\Data directory.
So, in short, I believe that VB6 is working as you expected it to, and most likely your program's inability to open a file is do to some other issue. As @StayOnTarget mentioned, if you could show your code someone here might be able to point out the problem.