Skip to content
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

How to list directory content #141

Closed
certik opened this issue Jul 21, 2020 · 15 comments
Closed

How to list directory content #141

certik opened this issue Jul 21, 2020 · 15 comments

Comments

@certik
Copy link
Member

certik commented Jul 21, 2020

In order to move beyond #137, we need a cross-platform way to read all the *.f90 files in a directory. What is the best way to do that in Fortran?

@milancurcic
Copy link
Member

For cross-platform you need this.

Otherwise, I think the next best kludge would be to call execute_command_line('ls > tmp.txt'), then parse tmp.txt, and equivalent on Windows.

@certik
Copy link
Member Author

certik commented Jul 21, 2020

We need a temporary solution so that we are not stuck on this, and can move on, and in the meantime we can work on the full general solution.

@milancurcic
Copy link
Member

I agree. I think wrapping around the shell commands on each OS is the way to go.

@certik
Copy link
Member Author

certik commented Jul 21, 2020

It seems like it. How do you determine which OS you are on from Fortran?

@milancurcic
Copy link
Member

milancurcic commented Jul 21, 2020

Perhaps we can test the value of an environment variable (get_environment_variable) that we know will be different between systems? Perhaps HOME, and then detect based on whether the value has forward slashes (Linux and macOS) or backslashes (Windows)? Just an idea, I've never done this myself.

@certik
Copy link
Member Author

certik commented Jul 21, 2020

Good idea, the GET_ENVIRONMENT_VARIABLE intrinsic will do this. That will get us started, and we can make this more robust / general later.

@everythingfunctional
Copy link
Member

I'd put it behind a function and just use preprocessor directives. Something like:

function is_windows()
    logical :: is_windows

#ifdef (WIN_32)
    is_windows = .true.
#elif
    is_windows = .false.
#endif

Obviously you'll need to look up the proper syntax and tests, but that way, even if you change the way it's done, it shouldn't require changing any other code anywhere.

@certik
Copy link
Member Author

certik commented Jul 21, 2020

@everythingfunctional ah that's right, I think that should work.

@milancurcic
Copy link
Member

I didn't know fpm supported preprocessing. 👍 in that case.

@everythingfunctional
Copy link
Member

fpm isn't doing any preprocessing, but our currently only supported compiler does a bit ;). Should be enough to solve at least the "Is this Windows or not?" question.

@arjenmarkus
Copy link
Member

I just tried: on Windows "dir /b" gives the bare list of file names, just as "ls". That means that only the command is different - not the format of the output (with out "/b" you get a lot of rubbish ;)).

@certik
Copy link
Member Author

certik commented Jul 22, 2020

@everythingfunctional so the ifdef trick does not work with gfortran to determine the OS, I tried that in #142, and it does not work on linux, nor anywhere else... Let's further discuss this OS determination in #144.

@certik
Copy link
Member Author

certik commented Jul 22, 2020

Thanks @arjenmarkus. I will try to do this once #142 is merged, as I need to determine the OS type first to know which command to run.

@interkosmos
Copy link
Member

Until stdlib can be included, perhaps linking an ISO C binding abstraction layer to either POSIX and Win32 routines at compile time may be sufficient.

@awvwgk
Copy link
Member

awvwgk commented Sep 5, 2021

This has been resolved by #507

@awvwgk awvwgk closed this as completed Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants