Skip to content

Commit bf14f0a

Browse files
committed
Extract stdlib_filesystem
1 parent e701d68 commit bf14f0a

9 files changed

+146
-117
lines changed

doc/specs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This is an index/directory of the specifications (specs) for each new module/fea
1717
- [constants](./stdlib_constants.html) - Constants
1818
- [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures
1919
- [error](./stdlib_error.html) - Catching and handling errors
20+
- [filesystem](./stdlib_filesystem.html) - Filesystem interactions
2021
- [hash](./stdlib_hash_procedures.html) - Hashing integer
2122
vectors or character strings
2223
- [hashmaps](./stdlib_hashmaps.html) - Hash maps/tables

doc/specs/stdlib_filesystem.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
title: filesystem
3+
---
4+
5+
# The `stdlib_filesystem` module
6+
7+
[TOC]
8+
9+
## Introduction
10+
11+
Module for filesystem interactions.
12+
13+
## Constants
14+
15+
### `is_windows``
16+
17+
Boolean constant indicating whether the current platform is Windows.
18+
19+
### `path_separator``
20+
21+
Character constant representing the path separator for the current platform. On Windows, it is `\`. On other platforms, it is `/`.
22+
23+
## Procedures
24+
25+
### `exists`
26+
27+
#### Status
28+
29+
Experimental
30+
31+
#### Description
32+
33+
Determines if a file or directory exists at the given path by returning a logical value.
34+
35+
#### Syntax
36+
37+
`exists = ` [[stdlib_filesystem(module):exists(function)]] `(path)`
38+
39+
#### Arguments
40+
41+
`path`: Shall be a character expression containing the path to a file or directory to check for existence.
42+
43+
#### Return value
44+
45+
A logical value indicating whether a file or directory exists at the given path.
46+
47+
### `list_dir`
48+
49+
#### Status
50+
51+
Experimental
52+
53+
#### Description
54+
55+
Lists the contents of a directory.
56+
57+
#### Syntax
58+
59+
`call ` [[stdlib_filesystem(module):list_dir(subroutine)]] `(dir, files[, iostat][, iomsg])`
60+
61+
#### Arguments
62+
63+
`dir`: Shall be a character expression containing the path to the directory to list.
64+
65+
`files`: Shall be an allocatable rank-1 array of type `string_type` that will contain the names of the files and directories in the directory.
66+
67+
`iostat`: Shall be a scalar of type `integer` that receives the error status of `list_dir`. Optional argument.
68+
69+
`iomsg`: Shall be a deferred length character variable that receives the error message of `list_dir`. Optional argument.
70+
71+
### `mkdir`
72+
73+
#### Status
74+
75+
Experimental
76+
77+
#### Description
78+
79+
Creates a new directory.
80+
81+
#### Syntax
82+
83+
`call ` [[stdlib_filesystem(module):mkdir(subroutine)]] `(dir[, iostat][, iomsg])`
84+
85+
#### Arguments
86+
87+
`dir`: Shall be a character expression containing the path to the directory to create.
88+
89+
`iostat`: Shall be a scalar of type `integer` that receives the error status of `mkdir`. Optional argument.
90+
91+
`iomsg`: Shall be a deferred length character variable that receives the error message of `mkdir`. Optional argument.
92+
93+
### `rmdir`
94+
95+
#### Status
96+
97+
Experimental
98+
99+
#### Description
100+
101+
Removes a directory.
102+
103+
#### Syntax
104+
105+
`call ` [[stdlib_filesystem(module):rmdir(subroutine)]] `(dir)`
106+
107+
#### Arguments
108+
109+
`dir`: Shall be a character expression containing the path to the directory to remove.
110+
111+
### `run`
112+
113+
#### Status
114+
115+
Experimental
116+
117+
#### Description
118+
119+
Runs a command in the shell.
120+
121+
#### Syntax
122+
123+
`call ` [[stdlib_filesystem(module):run(subroutine)]] `(command[, iostat][, iomsg])`
124+
125+
#### Arguments
126+
127+
`command`: Shall be a character expression containing the command to run in the shell.
128+
129+
`iostat`: Shall be a scalar of type `integer` that receives the error status of `run`. Optional argument.
130+
131+
`iomsg`: Shall be a deferred length character variable that receives the error message of `run`. Optional argument.

doc/specs/stdlib_io.md

-108
Original file line numberDiff line numberDiff line change
@@ -123,114 +123,6 @@ Provides a text file called `filename` that contains the rank-2 `array`.
123123
{!example/io/example_savetxt.f90!}
124124
```
125125

126-
## `exists`
127-
128-
### Status
129-
130-
Experimental
131-
132-
### Description
133-
134-
Determines if a file or directory exists at the given path by returning a logical value.
135-
136-
### Syntax
137-
138-
`exists = ` [[stdlib_io_filesystem(module):exists(function)]] `(path)`
139-
140-
### Arguments
141-
142-
`path`: Shall be a character expression containing the path to a file or directory to check for existence.
143-
144-
### Return value
145-
146-
A logical value indicating whether a file or directory exists at the given path.
147-
148-
## `list_dir`
149-
150-
### Status
151-
152-
Experimental
153-
154-
### Description
155-
156-
Lists the contents of a directory.
157-
158-
### Syntax
159-
160-
`call ` [[stdlib_io_filesystem(module):list_dir(subroutine)]] `(dir, files[, iostat][, iomsg])`
161-
162-
### Arguments
163-
164-
`dir`: Shall be a character expression containing the path to the directory to list.
165-
166-
`files`: Shall be an allocatable rank-1 array of type `string_type` that will contain the names of the files and directories in the directory.
167-
168-
`iostat`: Shall be a scalar of type `integer` that receives the error status of `list_dir`. Optional argument.
169-
170-
`iomsg`: Shall be a deferred length character variable that receives the error message of `list_dir`. Optional argument.
171-
172-
## `mkdir`
173-
174-
### Status
175-
176-
Experimental
177-
178-
### Description
179-
180-
Creates a new directory.
181-
182-
### Syntax
183-
184-
`call ` [[stdlib_io_filesystem(module):mkdir(subroutine)]] `(dir[, iostat][, iomsg])`
185-
186-
### Arguments
187-
188-
`dir`: Shall be a character expression containing the path to the directory to create.
189-
190-
`iostat`: Shall be a scalar of type `integer` that receives the error status of `mkdir`. Optional argument.
191-
192-
`iomsg`: Shall be a deferred length character variable that receives the error message of `mkdir`. Optional argument.
193-
194-
## `rmdir`
195-
196-
### Status
197-
198-
Experimental
199-
200-
### Description
201-
202-
Removes a directory.
203-
204-
### Syntax
205-
206-
`call ` [[stdlib_io_filesystem(module):rmdir(subroutine)]] `(dir)`
207-
208-
### Arguments
209-
210-
`dir`: Shall be a character expression containing the path to the directory to remove.
211-
212-
## `run`
213-
214-
### Status
215-
216-
Experimental
217-
218-
### Description
219-
220-
Runs a command in the shell.
221-
222-
### Syntax
223-
224-
`call ` [[stdlib_io_filesystem(module):run(subroutine)]] `(command[, iostat][, iomsg])`
225-
226-
### Arguments
227-
228-
`command`: Shall be a character expression containing the command to run in the shell.
229-
230-
`iostat`: Shall be a scalar of type `integer` that receives the error status of `run`. Optional argument.
231-
232-
`iomsg`: Shall be a deferred length character variable that receives the error message of `run`. Optional argument.
233-
234126
## `load_npy`
235127

236128
### Status

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(fppFiles
88
stdlib_bitsets_large.fypp
99
stdlib_codata_type.fypp
1010
stdlib_constants.fypp
11+
stdlib_filesystem.fypp
1112
stdlib_hash_32bit.fypp
1213
stdlib_hash_32bit_fnv.fypp
1314
stdlib_hash_32bit_nm.fypp
@@ -17,7 +18,6 @@ set(fppFiles
1718
stdlib_hash_64bit_pengy.fypp
1819
stdlib_hash_64bit_spookyv2.fypp
1920
stdlib_io.fypp
20-
stdlib_io_filesystem.fypp
2121
stdlib_io_npy.fypp
2222
stdlib_io_npy_load.fypp
2323
stdlib_io_npy_save.fypp

src/stdlib_io_filesystem.fypp renamed to src/stdlib_filesystem.fypp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
! SPDX-Identifier: MIT
22

33
!> Interaction with the filesystem.
4-
module stdlib_io_filesystem
4+
module stdlib_filesystem
55
use stdlib_string_type, only: string_type
66
implicit none
77
private
88

99
public :: temp_dir, is_windows, exists, path_separator, list_dir, mkdir, rmdir, run
1010

1111
#: if OS == 'Windows'
12+
!> Whether the operating system is Windows.
1213
logical, parameter :: is_windows = .true.
14+
!> Path separator for Windows.
1315
character, parameter :: path_separator = '\'
1416
#: else
17+
!> Whether the operating system is Windows.
1518
logical, parameter :: is_windows = .false.
19+
!> Path separator for filesystems on non-Windows operating systems.
1620
character, parameter :: path_separator = '/'
1721
#: endif
1822

@@ -22,7 +26,7 @@ contains
2226
!> Version: experimental
2327
!>
2428
!> Whether a file or directory exists at the given path.
25-
!> [Specification](../page/specs/stdlib_io.html#exists)
29+
!> [Specification](../page/specs/stdlib_filesystem.html#exists)
2630
logical function exists(path)
2731
!> Path to a file or directory.
2832
character(len=*), intent(in) :: path
@@ -37,7 +41,7 @@ contains
3741
!> Version: experimental
3842
!>
3943
!> List files and directories of a directory. Does not list hidden files.
40-
!> [Specification](../page/specs/stdlib_io.html#list_dir)
44+
!> [Specification](../page/specs/stdlib_filesystem.html#list_dir)
4145
subroutine list_dir(dir, files, iostat, iomsg)
4246
!> Directory to list.
4347
character(len=*), intent(in) :: dir
@@ -95,7 +99,7 @@ contains
9599
!> Version: experimental
96100
!>
97101
!> Create a directory.
98-
!> [Specification](../page/specs/stdlib_io.html#mkdir)
102+
!> [Specification](../page/specs/stdlib_filesystem.html#mkdir)
99103
subroutine mkdir(dir, iostat, iomsg)
100104
character(len=*), intent(in) :: dir
101105
integer, optional, intent(out) :: iostat
@@ -111,7 +115,7 @@ contains
111115
!> Version: experimental
112116
!>
113117
!> Remove a directory including its contents.
114-
!> [Specification](../page/specs/stdlib_io.html#rmdir)
118+
!> [Specification](../page/specs/stdlib_filesystem.html#rmdir)
115119
subroutine rmdir(dir)
116120
character(len=*), intent(in) :: dir
117121

@@ -125,7 +129,7 @@ contains
125129
!> Version: experimental
126130
!>
127131
!> Run a command in the shell.
128-
!> [Specification](../page/specs/stdlib_io.html#run)
132+
!> [Specification](../page/specs/stdlib_filesystem.html#run)
129133
subroutine run(command, iostat, iomsg)
130134
!> Command to run.
131135
character(len=*), intent(in) :: command

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_subdirectory(array)
1414
add_subdirectory(ascii)
1515
add_subdirectory(bitsets)
1616
add_subdirectory(constants)
17+
add_subdirectory(filesystem)
1718
add_subdirectory(hash_functions)
1819
add_subdirectory(hash_functions_perf)
1920
add_subdirectory(hashmaps)

test/filesystem/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ADDTEST(filesystem)

test/io/test_filesystem.f90 renamed to test/filesystem/test_filesystem.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module test_filesystem
2-
use stdlib_io_filesystem
2+
use stdlib_filesystem
33
use stdlib_string_type, only: char, string_type
44
use testdrive, only: new_unittest, unittest_type, error_type, check, test_failed
55
implicit none

test/io/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ADDTEST(savetxt_qp)
1313
set_tests_properties(loadtxt_qp PROPERTIES LABELS quadruple_precision)
1414
set_tests_properties(savetxt_qp PROPERTIES LABELS quadruple_precision)
1515

16-
ADDTEST(filesystem)
1716
ADDTEST(getline)
1817
ADDTEST(npy)
1918
ADDTEST(open)

0 commit comments

Comments
 (0)