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

ID 767251
Date 3/22/2024
Public

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

Document Table of Contents

FULLPATHQQ

Portability Function: Returns the full path for a specified file or directory.

Module

USE IFPORT

result = FULLPATHQQ (name,pathbuf)

name

(Input) Character*(*). Item for which you want the full path. Can be the name of a file in the current directory, a relative directory or file name, or a network uniform naming convention (UNC) path.

pathbuf

(Output) Character*(*). Buffer to receive full path of the item specified in name.

Results

The result type is INTEGER(4). The result is the length of the full path in bytes, or 0 if the function fails. This function does not verify that the resulting path and file name are valid nor that they exist.

The length of the full path depends upon how deeply the directories are nested on the drive you are using. If the full path is longer than the character buffer provided to return it ( pathbuf), FULLPATHQQ returns only that portion of the path that fits into the buffer.

Check the length of the path before using the string returned in pathbuf. If the longest full path you are likely to encounter does not fit into the buffer you are using, allocate a larger character buffer. You can allocate the largest possible path buffer with the following statements:

  USE IFPORT
  CHARACTER($MAXPATH) pathbuf

$MAXPATH is a symbolic constant defined in IFPORT.F90 as 260.

Example

     USE IFPORT
     USE IFCORE
     CHARACTER($MAXPATH) buf
     CHARACTER(3)        drive
     CHARACTER(256)      dir
     CHARACTER(256)      name
     CHARACTER(256)      ext
     CHARACTER(256)      file
     INTEGER(4)          len
     DO WHILE (.TRUE.)
       WRITE (*,*)
       WRITE (*,'(A, \)') ' Enter filename (Hit &
                            RETURN to exit): '
       len = GETSTRQQ(file)
       IF (len .EQ. 0) EXIT
       len = FULLPATHQQ(file, buf)
       IF (len .GT. 0) THEN
         WRITE (*,*) buf(:len)
       ELSE
         WRITE (*,*) 'Can''t get full path'
         EXIT
       END IF
!
!      Split path
       WRITE (*,*)
       len = SPLITPATHQQ(buf, drive, dir, name, ext)
       IF (len .NE. 0) THEN
         WRITE (*, 900) ' Drive: ', drive
         WRITE (*, 900) ' Directory: ', dir(1:len)
         WRITE (*, 900) ' Name: ', name
         WRITE (*, 900) ' Extension: ', ext
       ELSE
         WRITE (*, *) 'Can''t split path'
       END IF
     END DO
900  FORMAT (A, A)
     END

See Also