-
Notifications
You must be signed in to change notification settings - Fork 192
feat: exists
to return the type of a path
#1026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wassup05
wants to merge
21
commits into
fortran-lang:master
Choose a base branch
from
wassup05:exists
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+650
−30
Open
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
42c839c
add functions, parameters
wassup05 8510867
add C interfaces
wassup05 866fddb
added examples
wassup05 aebb335
added tests
wassup05 cd61274
added docs
wassup05 4ec8097
better test fail messages
wassup05 661ec55
fix windows reg file
wassup05 dd10b5a
fix test commands
wassup05 5be9e94
improve test
wassup05 1aa265d
typos + small changes
wassup05 306bc86
better docs
wassup05 a5a340e
type renaming + docs
wassup05 2c738a8
add `is_regular_file` and `is_symlink`
wassup05 2b3f141
add docs for the new functions
wassup05 9f5655a
FORD docs
wassup05 1613fb5
new test for `is_regular_file`
wassup05 e6c6a21
new examples
wassup05 713ed1c
fix broken links
wassup05 39ab1b7
misc changes
wassup05 029860f
Merge branch 'master' into exists
wassup05 95b47ec
`is_regular_file` -> `is_file`
wassup05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
! Illustrate the usage of `exists` | ||
program example_exists | ||
use stdlib_system, only: exists, fs_type_unknown, fs_type_regular_file, & | ||
fs_type_directory, fs_type_symlink | ||
use stdlib_error, only: state_type | ||
implicit none | ||
|
||
type(state_type) :: err | ||
|
||
! Path to check | ||
character(*), parameter :: path = "path/to/check" | ||
! To get the type of the path | ||
integer :: t | ||
|
||
t = exists(path, err) | ||
|
||
if (err%error()) then | ||
! An error occured, print it | ||
print *, err%print() | ||
end if | ||
|
||
! switching on the type returned by `exists` | ||
select case (t) | ||
case (fs_type_unknown); print *, "Unknown type!" | ||
case (fs_type_regular_file); print *, "Regular File!" | ||
case (fs_type_directory); print *, "Directory!" | ||
case (fs_type_symlink); print *, "Symbolic Link!" | ||
end select | ||
end program example_exists | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
! Demonstrate usage of `is_regular_file` | ||
program example_is_regular_file | ||
use stdlib_system, only: is_regular_file | ||
implicit none | ||
|
||
character(*), parameter :: path = "path/to/check" | ||
|
||
! Test if path is a regular file | ||
if (is_regular_file(path)) then | ||
print *, "The specified path is a regular file." | ||
else | ||
print *, "The specified path is not a regular file." | ||
end if | ||
end program example_is_regular_file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
! Demonstrate usage of `is_symlink` | ||
program example_is_symlink | ||
use stdlib_system, only: is_symlink, is_directory | ||
implicit none | ||
|
||
character(*), parameter :: path = "path/to/check" | ||
|
||
! Test if path is a symbolic link | ||
if (is_symlink(path)) then | ||
print *, "The specified path is a symlink." | ||
! Further check if it is linked to a file or a directory | ||
if (is_directory(path)) then | ||
print *, "Further, it is a link to a directory." | ||
else | ||
print *, "Further, it is a link to a file." | ||
end if | ||
else | ||
print *, "The specified path is not a symlink." | ||
end if | ||
end program example_is_symlink |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are advertising it, would it be reaonable to add a test that checks
./test_file
on all systems, and also.\test_file
on WindowsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand what you mean, do you mean a sort of utility test function to make the tests simpler and extensive by checking both the kinds of paths for all the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it would be useful if the tests tested
filename
but also./filename
(on all OSes) and.\filename
(on Windows only)