Consider this VB6 code:
Assuming that the TestDir string is a full path to a directory that exists, that directory should be shown in the messagebox. If you test it out, it will perform as expected.Code:Dim TestDir As String TestDir = "d:\testdir" ChDrive Left(TestDir, 1) ChDir TestDir ChDrive "c:" MsgBox CurDir(Left(TestDir, 1))
Now consider this VB.NET code:
This code should do the same exact thing as the VB6 code I just showed you. In fact, it was the Visual Studio .NET IDE that converted the code for me.Code:Dim TestDir As String TestDir = "d:\testdir" ChDrive(Left(TestDir, 1)) ChDir(TestDir) ChDrive("c:") MsgBox(CurDir(Left(TestDir, 1)))
If you run that VB.NET code, the directory shown in the message box doesn't seem to be the same as the one in TestDir if the directory in TestDir is on any drive other than drive C (or whichever drive that last ChDrive line changes to). Did I just find a bug, or did I miss something, or did something completely different happen?
NOTE: the culprit appears to be this line (taken from the VB.NET code):
ChDrive("c:")
Apparently, it's changing the current path on the drive it's changing from in the process of changing the current drive. Changing that line to either of the following two lines doesn't fix anything:
System.Environment.CurrentDirectory = "c:"
System.IO.Directory.SetCurrentDirectory("c:")




Reply With Quote