Q(uick)BASIC Function: CURDIR$
Quick View
CURDIR\$
Returns the path currently in use for the specified drive
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- CURDIR$[(drive$)]
Description/Parameter(s)
drive$ | A string expression that specifies a drive. |
- The argument drive$ must be in the range A to lastdrive, where lastdrive is the maximum drive letter you set in your CONFIG.SYS file.
- If no drive is specified or if drive$ is a null string, CURDIR$ returns the path for the currently selected drive. This is similar to using the CHDIR command at the system prompt without specifying a path.
Usage Notes
- BASIC generates an error if the first character in the argument drive$ lies outside the range A to lastdrive, unless you are working in a networked environment.
- BASIC also generates an error if the first character in the argument drive$ corresponds to a drive that does not exist, or if the first letter in the argument drive$ is not a letter.
- CURDIR$ is not case sensitive. "C" is the same as "c."
Example
This example uses the CURDIR$ function and the CHDRIVE statement within the ChangeDataDrive SUB procedure. CURDIR$ is used to determine the current drive from a given file specification. CHDRIVE changes to a new default drive if the one specified is different from the current drive.
DECLARE SUB ChangeDataDrive (filespec$)
ON ERROR RESUME NEXT
filespec$ = "A:"
ChangeDataDrive filespec$
filespec$ = "C:\DOS"
ChangeDataDrive filespec$
SUB ChangeDataDrive (filespec$)
'This SUB procedure evaluates a file specification and changes the
'currently logged drive to the specified drive (if any). The procedure
'contains no error handling.
curdrive$ = LEFT$(CURDIR$, 2) 'Get the current drive.
'Determine if there is a drive name on the filespec.
IF INSTR(1, filespec$, ":") = 2 THEN
newdrive$ = LEFT$(filespec$, 2)
ELSE
newdrive$ = curdrive$
END IF
'Ensure that the new drive is different from the
'currently logged drive.
IF newdrive$ <> curdrive$ THEN
CHDRIVE newdrive$ 'It isn't, so change it.
PRINT "Logged drive changed from "; curdrive$; " to "; newdrive$
ELSE 'It is, so don't change it.
PRINT "New drive same as logged drive. No change occurred."
END IF
END SUB
See also: