From: qquito on
Dear Everyone:

I have used the INQUIRE statement in Fortran 90 to determine if a file
with a given name exists or not. Now I need to determine if a
DIRECTORY is empty or not. Can I use the INQUIRE to do the job? And
how? If not, is there any other function in Fortran 90 that can do the
job?

Thank you for reading and replying!

--Roland
From: Sjouke Burry on
qquito wrote:
> Dear Everyone:
>
> I have used the INQUIRE statement in Fortran 90 to determine if a file
> with a given name exists or not. Now I need to determine if a
> DIRECTORY is empty or not. Can I use the INQUIRE to do the job? And
> how? If not, is there any other function in Fortran 90 that can do the
> job?
>
> Thank you for reading and replying!
>
> --Roland

By examining a redirected dir command in a system() call??

In a windows flavor:
call system('dir/b [your_path_and_dir] > [somepathplusfile]')

after which you read [somepathplusfile], to find out whether
your dir is empty.
From: Richard Maine on
qquito <qquito(a)hotmail.com> wrote:

> I have used the INQUIRE statement in Fortran 90 to determine if a file
> with a given name exists or not. Now I need to determine if a
> DIRECTORY is empty or not. Can I use the INQUIRE to do the job? And
> how? If not, is there any other function in Fortran 90 that can do the
> job?

The Fortran language does not even have the concept of a directory. So
you need something system specific. As Sjouke suggests, one such system
specific way would be to capture the output of an appropriate shell
command (though note that the SYSTEM subroutine that he mentions is also
nonstandard, though things like it are reasonably common extensions).

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: qquito on
On Mar 4, 11:47 pm, nos...(a)see.signature (Richard Maine) wrote:
> qquito <qqu...(a)hotmail.com> wrote:
> > I have used the INQUIRE statement in Fortran 90 to determine if a file
> > with a given name exists or not. Now I need to determine if a
> > DIRECTORY is empty or not. Can I use the INQUIRE to do the job? And
> > how? If not, is there any other function in Fortran 90 that can do the
> > job?
>
> The Fortran language does not even have the concept of a directory. So
> you need something system specific. As Sjouke suggests, one such system
> specific way would be to capture the output of an appropriate shell
> command (though note that the SYSTEM subroutine that he mentions is also
> nonstandard, though things like it are reasonably common extensions).

Thank you, Richard and Sjouke, for your replies!

I use a Mac OS X machine under a Bash Shell, and I have found a
command

% ["$(ls -A Mydirectory)"] && echo "1" || echo "0"

If Mydirectory is empty, I get 0; if not, I get 1. And I can use "call
system()" to execute the above.

But the question is: How can I capture the output of either 0 or 1
from the above with a variable defined by me in my Fortran 90 code?

--Roland
From: baf on
On 3/4/2010 10:27 PM, qquito wrote:
> On Mar 4, 11:47 pm, nos...(a)see.signature (Richard Maine) wrote:
>> qquito<qqu...(a)hotmail.com> wrote:
>>> I have used the INQUIRE statement in Fortran 90 to determine if a file
>>> with a given name exists or not. Now I need to determine if a
>>> DIRECTORY is empty or not. Can I use the INQUIRE to do the job? And
>>> how? If not, is there any other function in Fortran 90 that can do the
>>> job?
>>
>> The Fortran language does not even have the concept of a directory. So
>> you need something system specific. As Sjouke suggests, one such system
>> specific way would be to capture the output of an appropriate shell
>> command (though note that the SYSTEM subroutine that he mentions is also
>> nonstandard, though things like it are reasonably common extensions).
>
> Thank you, Richard and Sjouke, for your replies!
>
> I use a Mac OS X machine under a Bash Shell, and I have found a
> command
>
> % ["$(ls -A Mydirectory)"]&& echo "1" || echo "0"
>
> If Mydirectory is empty, I get 0; if not, I get 1. And I can use "call
> system()" to execute the above.
>
> But the question is: How can I capture the output of either 0 or 1
> from the above with a variable defined by me in my Fortran 90 code?
>
> --Roland

Redirect the output to a file

% ["$(ls -A Mydirectory)"]&& echo "1" || echo "0" > directory_status

Then open and read the file with Fortran