ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
CHDRIVE Statement and CURDIR$ Function Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' 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.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 CLS                                      ' Clear the screen
 DECLARE SUB ChangeDataDrive (filespec$)
 ON ERROR RESUME NEXT
 filespec$ = "A:"
 ChangeDataDrive filespec$
 filespec$ = "C:\DOS"
 ChangeDataDrive filespec$
 
 SUB ChangeDataDrive (filespec$)
     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