CHDIR function

Purpose:

Use CHDIR to change to a specified directory

Syntax:

RetVal = CHDIR(DirectoryName AS STRING)

Return Value:

  • Data type: INTEGER
    RetVal If the change to the specified directory is successful, 0 is returned. If not successful, -1 is returned.

Parameters:

  • Data type: STRING
    DirectoryName String literal or variable containing name of the directory to which to change.

Example:

DIM IsIt%
DIM DirectoryName$
DIM RetVal%

DirectoryName$ = "C:\Windows\Temp"

IsIt% = EXIST(DirectoryName$)
IF IsIt% = 1 THEN
  RetVal% = CHDIR(DirectoryName$)
  IF RetVal% = 0 THEN
    PRINT "CHDIR changed the current directory to " & CURDIR$
  ELSEIF RetVal% = -1 THEN
    PRINT "CHDIR could not change the current directory."
  END IF
ELSEIF IsIt% = 0 THEN
  PRINT DirectoryName$ & " directory does not exist."
END IF

Result:

CHDIR changed the current directory to C:\Windows\Temp