LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change the pathname

I would like to be able to change the current pathname in my code.
 
The are two functions:
       SetDrive () and SetDir ();
 
Ideally I would like to perform this completely in one function, but the function SetDir does not support drive names. The problem with the function SetDrive is that it requires me to set the drive by its logical number and I need to reference it by its drivename. Is there a function to look up the logical number of the current machine from the drive letter? What is the best way to set the active path?
0 Kudos
Message 1 of 4
(3,468 Views)

Hi Steve.

From the help on SetDrive():
"The mapping between the drive number and the logical drive letter is 0 = A, 1 = B, and so on.

Values: 0—25."

So, for example, to make E: the current drive:
  char driveLetter = 'E';
  int driveNumber, status;
  ...
  driveNumber = driveLetter - 'A';
  status = SetDrive (driveNumber);

Alernatively, you could use the Windows SDK function SetCurrentDirectory(), which sets the drive and directory in one call.

Cheers,
Colin.

0 Kudos
Message 2 of 4
(3,440 Views)
But what if not all letters exist. If a machine has an A, C, and M drive, but no B and drives between C and M, is C still mapped as the third drive or is it mapped as the second?
0 Kudos
Message 3 of 4
(3,416 Views)
the number passed to SetDrive() is not the drive number but a number which identifies a letter, with A=0, B=1, etc... (this is inherited from the good old days of DOS systems, mainly unnecessary nawadays)

so in the case of a system having the A, C and M drive: C is still the third letter and identified by 3, M by the number 13 and A by the number 1. calling SetDrive() with an invalid drive letter should return an error (-1 according to the documentation)
0 Kudos
Message 4 of 4
(3,406 Views)