Changes the filename of a path (keeping the path).
l = replace_filename(fname, newname)
Where:
fname
: Name or path of the file.newname
: New name for the name filename (including extension).It returns the fname value with the modified name.
The following program changes the filename of some paths.
PROGRAM replace_filenameExample
USE FU_Files, ONLY: replace_filename
IMPLICIT NONE
CHARACTER(LEN=:), ALLOCATABLE :: path
path='file1.txt'
WRITE(*,*) path, ' ', replace_filename(path, 'file2')
path='./file1.txt'
WRITE(*,*) path, ' ', replace_filename(path, 'file2')
path='/tmp/file1.txt'
WRITE(*,*) path, ' ', replace_filename(path, 'file2')
path='/tmp/file1.dat'
WRITE(*,*) path, ' ', replace_filename(path, '')
path='/tmp/file1'
WRITE(*,*) path, ' ', replace_filename(path, 'file2')
END PROGRAM replace_filenameExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | fname |
Filename or path to a file. |
||
character(len=*), | intent(in) | :: | newname |
New filename for the fname (including extension). |
The fname value with the modified filename.