Intel® Fortran Compiler 18.0 Developer Guide and Reference
Portability Function: Changes the default directory.
USE IFPORT
result = CHDIR(dir_name)
dir_name |
(Input) Character*(*). Name of a directory to become the default directory. |
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.
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