The folder name problem

maximc

Member
Joined
Apr 16, 2005
Messages
18
Programming Experience
1-3
I am using the in-built Shell() function to call a VB6 routine and the .exe file lies in a folder that has spaces. For example "My Documents" is embedded within my path for the .exe file that I am executing. Because of the space between "My" and "Documents", the program tells me that it could not find the file. However, if I move my entire project to the root folder where there is no space to my folder name, the project executes without any problem. I tried writing a routine that would add inverted quotes (") before and after the folder "My Documents" but to no avail. Can someone help me know how to get rid of this problem?
P.S. the reason why I am calling a VB6 routine is because I don't have a compatible .Net driver to connect to DB2 database.
 
You may need to use the Chr function to generate a squote
character around the spacey directory name.

Also just for fun run a command window and type in:
dir doc* /X

You will see a shorter name for the 'documents and settings' folder
 
Can you show us the actual code you're using because it sounds like it may be wrong on a number of levels. If you want to execute a file located in your "My Documents" folder then the code should look something like this:
VB.NET:
Process.Start(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "file name"))
 
Also, how is it that you can connect to DB2 from VB6 and not VB.NET? If you have an ODBC driver installed, which I assume that you must if you're connection with VB6, then you would use the same driver in VB.NET via an OdbcConnection object.
 
Can you show us the actual code you're using because it sounds like it may be wrong on a number of levels. If you want to execute a file located in your "My Documents" folder then the code should look something like this:
VB.NET:
Process.Start(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "file name"))

Well, since the folder name is dynamic, I may not be sure if the directory name would be "My Documents" or not. So I wrote a function called GetFileName which would add quotes (") before and after the folder name that has spaces. However, the problem still persisted. The code that I am using is as follows:
ExecFile = Func.GetFileName(MyPath + "\..\..\AIMvb6\tickets.exe") + _
" " + VB6Param + " 4"
ProcID = Shell(ExecFile, AppWinStyle.NormalFocus)
AppActivate(ProcID)

The folder structure of my project is as follows: The name of my main folder is MyAIM. Within this folder, I have two folders named AIM and AIMVB6. The AIM folder is the .Net Project and the AIMVB6 folder is the VB6 program which I am calling. When my project gets executed, I will be in the folder D:\MyAIM\AIM\bin\AIM.exe. From here, I need to call the VB6 program. So, the resulting folder would be MyPath + "\..\..\AIMVB6\tickets.exe". Since the project can be deployed in any path that the user selects, I want to accordingly execute the .exe file from that path.
 
Also, how is it that you can connect to DB2 from VB6 and not VB.NET? If you have an ODBC driver installed, which I assume that you must if you're connection with VB6, then you would use the same driver in VB.NET via an OdbcConnection object.

Well, I have a driver called "Client Access Express" which works only on VB6, but on .Net it fails sometimes to retrieve data. I checked the IBM site and they said that I need to have "DB2 .Net Data Provider" from IBM if I need to connect to DB2 database from .Net. That is the reason why I am calling the VB6 routine to get my job done. And I have no hassles except for the one that I mentioned in this thread.
 
Hi Guys, I got the solution to my problem. You need to do the following:

ExecFile = Func.GetFileName(MyPath + "\..\..\AIMvb6\tickets.exe")
MyFileInfo =
New FileInfo(ExecFile)
Proc.Start(MyFileInfo.FullName)

P.S. GetFileName is my routine where I add quotes (") to any folder that has spaces. Secondly, FileInfo is a method in System.IO

 
FileInfo is a class, not a method.
Yes, FileInfo is a class - sorry about the misinformation from my side. Secondly, in the code that I've written above as the solution, for folder names with spaces, it need not be embedded within quotes. Please do note the correction.
 
Back
Top