Skip to content

Commit f7ef8f6

Browse files
committed
add example
1 parent 7346b8e commit f7ef8f6

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

doc/specs/stdlib_system.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,5 @@ The file is removed from the filesystem if the operation is successful. If the o
530530
### Example
531531

532532
```fortran
533-
program example_delete_file
534-
use stdlib_fs
535-
implicit none
536-
537-
type(state_type) :: err
538-
539-
! Delete a file with error handling
540-
call delete_file("example.txt", err)
541-
542-
if (err%error()) then
543-
print *, "Failed to delete file:", err%print()
544-
else
545-
print *, "File deleted successfully."
546-
end if
547-
end program example_delete_file
533+
{!example/system/example_delete_file.f90!}
548534
```

example/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ADD_EXAMPLE(get_runtime_os)
2+
ADD_EXAMPLE(delete_file)
23
ADD_EXAMPLE(is_directory)
34
ADD_EXAMPLE(null_device)
45
ADD_EXAMPLE(os_type)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! Demonstrate usage of `delete_file`
2+
program example_delete_file
3+
use stdlib_system, only: delete_file
4+
use stdlib_error, only: state_type
5+
implicit none
6+
7+
type(state_type) :: err
8+
character(*), parameter :: filename = "example.txt"
9+
10+
! Delete a file with error handling
11+
call delete_file(filename, err)
12+
13+
if (err%error()) then
14+
print *, err%print()
15+
else
16+
print *, "File "//filename//" deleted successfully."
17+
end if
18+
end program example_delete_file

0 commit comments

Comments
 (0)