Sun Studio 12: Fortran Library Reference

1.4.5 chdir: Change Default Directory

The function is called by:

INTEGER*4 chdir

n = chdir( dirname )

dirname

character

Input 

Directory name 

Return value 

INTEGER*4

Output 

n=0: OK, n>0: Error code

Example: chdir—change cwd to MyDir:


       INTEGER*4  chdir, n
       n =  chdir ( ’MyDir’ )
       if ( n .ne. 0 ) stop ’chdir: error’
       end

See also: chdir(2), cd(1), and gerror(3F) to interpret error codes.

Path names can be no longer than MAXPATHLEN as defined in <sys/param.h>. They can be relative or absolute paths.

Use of this function can cause inquire by unit to fail.

Certain Fortran file operations reopen files by name. Using chdir while doing I/O can cause the runtime system to lose track of files created with relative path names. including the files that are created by open statements without file names.