Description
So, following the suggestion in #201, let's start to discuss file system access API. In order to keep it focused, I'd suggest to start with the directory related operations first. My proposal:
open_directory(dirname, dirdesc, status)
: Opens a directory and returns a descriptor
type(dirdesc_t)
: Type containing the data of an opened directory
dirdesc_t%get_next()
: Returns the next entry in the open directory or ""
if
there are no more entries.
make_directory(dirname, parents, status)
: Makes a directory. If parents
is .true.
also parent directories are created in case they do not exist yet.
remove_directory(dirname, content, status)
: Removes a directory. If content
is
.true.
also the directory content is removed (recursive delete).
change_directory(dirname, status)
: Changes to the given directory
get_working_dir() -> char(:), allocatable
: Returns the current working directory.
is_dir(fname) -> logical
: GIve .true.
if fname
is a directory.
A few notes:
-
The functionality above can be easily realized with a libc-interface (should work on all POSIX systems) and a bit of C-code. The big question is Windows, as I have no clue how to implement this functionality on WIndows.
-
As for error handling we could have a status argument. I'd argue for having a derived type
type(status_t)
containg the result of the operation (OK/Error) and a string with the error message in case of error. Whether the status argument should be optional or not is open for discussions.