Intel® Fortran Compiler 18.0 Developer Guide and Reference

CHDIR

Portability Function: Changes the default directory.

Module

USE IFPORT

result = CHDIR(dir_name)

dir_name

(Input) Character*(*). Name of a directory to become the default directory.

Results

The result type is INTEGER(4). It returns zero if the directory was changed successfully; otherwise, an error code. Possible error codes are:

Example

     use ifport
     integer(4) istatus, enoent, enotdir
     character(255)  newdir
     character(300)  prompt, errmsg

     prompt = 'Please enter directory name: '
10   write(*,*)  TRIM(prompt)
     read *, newdir
     ISTATUS = CHDIR(newdir)
     select case (istatus)
       case (2)  ! ENOENT
         errmsg = 'The directory '//TRIM(newdir)//' does not exist'
       case (20) ! ENOTDIR
         errmsg = TRIM(newdir)//' is not a directory'
       case (0) ! NO error
         goto 40
       case default
         write (errmsg,*) 'Error with code ', istatus
      end select

      write(*,*)  TRIM(errmsg)
      goto 10

40    write(*,*) 'Default directory successfully changed.'
end

See Also