Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/31/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

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:

  • ENOENT: The named directory does not exist.

  • ENOTDIR: The dir_name parameter is not a directory.

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