Using INQUIRE to test if a directory exists

This is a discussion on Using INQUIRE to test if a directory exists within the Fortran forums in Programming Languages category; INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests for the existence of a directory with all my Windows compilers (g95,gfortran,lf95) except IVF. Does anybody know the reason for this and what the standard says if anything? Al Greynolds www.ruda.com...

Go Back   Application Development Forum > Programming Languages > Fortran

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-21-2008, 05:18 PM
Al Greynolds
Guest
 
Default Using INQUIRE to test if a directory exists

INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests
for the existence of a directory with all my Windows compilers
(g95,gfortran,lf95) except IVF. Does anybody know the reason for this
and what the standard says if anything?

Al Greynolds
www.ruda.com


Reply With Quote
  #2  
Old 08-21-2008, 05:31 PM
Gary Scott
Guest
 
Default Re: Using INQUIRE to test if a directory exists

Al Greynolds wrote:

> INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests
> for the existence of a directory with all my Windows compilers
> (g95,gfortran,lf95) except IVF. Does anybody know the reason for this
> and what the standard says if anything?


it would be ambiguous? On some systems, there isn't even a concept of a
directory. There may be a "qualifier/account number" associated, but
nothing like a directory, so the standard shouldn't really say that a
"file" and a "directory" should be detected portably across OS'. There
are situations when you actually want to differentiate between a file
and a directory, and you can't using this syntax without prior
knowledge. Didn't IVF add some extensions specifically for querying
directories? CVF does handle directories with the above inquire statement.

>
> Al Greynolds
> www.ruda.com
>
>



--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Reply With Quote
  #3  
Old 08-21-2008, 05:44 PM
Al Greynolds
Guest
 
Default Re: Using INQUIRE to test if a directory exists

On Aug 21, 2:31*pm, Gary Scott <garylsc...@sbcglobal.net> wrote:
> Didn't IVF add some extensions specifically for querying
> directories?


Yes they did, but I was looking for something that is portable (at
least among the compilers I use). Its interesting that they changed
the default behavior from CVF to IVF.

Anyway its not a big deal just a curiosity.

Al
Reply With Quote
  #4  
Old 08-21-2008, 08:55 PM
Richard Maine
Guest
 
Default Re: Using INQUIRE to test if a directory exists

Al Greynolds <awgreynolds@earthlink.net> wrote:

> INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests
> for the existence of a directory with all my Windows compilers
> (g95,gfortran,lf95) except IVF. Does anybody know the reason for this
> and what the standard says if anything?


The Fortran standard does not even have the concept of a directory (and
Fortran has been implemented on systems that don't have such a thing),
so it says nothing about it.

As I recall, the C standard is actually quite simillar in not having
such a concept. Sure there are widely used C libraries that do, but I
don't recall that it was directly in the C standard.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
Reply With Quote
  #5  
Old 08-21-2008, 11:18 PM
Gary Scott
Guest
 
Default Re: Using INQUIRE to test if a directory exists

Al Greynolds wrote:

> On Aug 21, 2:31 pm, Gary Scott <garylsc...@sbcglobal.net> wrote:
>
>>Didn't IVF add some extensions specifically for querying
>>directories?

>
>
> Yes they did, but I was looking for something that is portable (at
> least among the compilers I use). Its interesting that they changed
> the default behavior from CVF to IVF.


I'm pretty sure I was one that complained about the way DVF or CVF
implemented this. I had a specific situation where I needed to
differentiate a directory from a file (file names don't have to have
extensions/types suffixed to them). So I may or may not have had some
tiny influence on it being changed (don't know, assume it would take
lots of complaints or some other serious reason to change it).

>
> Anyway its not a big deal just a curiosity.
>
> Al



--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Reply With Quote
  #6  
Old 08-22-2008, 12:40 AM
Terence
Guest
 
Default Re: Using INQUIRE to test if a directory exists

I heard that one trick is to quote the directory name followed by
".nul' as the filename to test for.
This was supposed to return a .TRUE. response if the directory
existed.
But this may be platform dependent.

Note: this is a memory, which may be wrong.
I personally use non-portable methods myself..
Reply With Quote
  #7  
Old 08-22-2008, 02:51 AM
Arjen Markus
Guest
 
Default Re: Using INQUIRE to test if a directory exists

On 21 aug, 23:18, Al Greynolds <awgreyno...@earthlink.net> wrote:
> INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests
> for the existence of a directory with all my Windows compilers
> (g95,gfortran,lf95) except IVF. *Does anybody know the reason for this
> and what the standard says if anything?
>
> Al Greynoldswww.ruda.com


On Windows and Linux/UNIX/OSX a directory contains a special
file named ".". You might try:

INQUIRE( FILE = 'mydirectory/.', EXIST = exists )

Regards,

Arjen
Reply With Quote
  #8  
Old 08-22-2008, 07:38 AM
fj
Guest
 
Default Re: Using INQUIRE to test if a directory exists

On 22 août, 08:51, Arjen Markus <arjen.mar...@wldelft.nl> wrote:
> On 21 aug, 23:18, Al Greynolds <awgreyno...@earthlink.net> wrote:
>
> > INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests
> > for the existence of a directory with all my Windows compilers
> > (g95,gfortran,lf95) except IVF. Does anybody know the reason for this
> > and what the standard says if anything?

>
> > Al Greynoldswww.ruda.com

>
> On Windows and Linux/UNIX/OSX a directory contains a special
> file named ".". You might try:
>
> INQUIRE( FILE = 'mydirectory/.', EXIST = exists )
>
> Regards,
>
> Arjen


To be a little bit more portable, I also use an environment variable
called for instance DELIMITER which is equals to "\" on Windows and
"/" on unix :

CHARACTER :: delimiter
...
CALL get_environment_variable('DELIMITER',delimiter)
INQUIRE(file='mydirectory'//delimiter//'.',EXIST=exist)
Reply With Quote
  #9  
Old 08-22-2008, 08:07 AM
Arjen Markus
Guest
 
Default Re: Using INQUIRE to test if a directory exists

On 22 aug, 13:38, fj <francois.j...@irsn.fr> wrote:
> On 22 août, 08:51, Arjen Markus <arjen.mar...@wldelft.nl> wrote:
>
>
>
>
>
> > On 21 aug, 23:18, Al Greynolds <awgreyno...@earthlink.net> wrote:

>
> > > INQUIRE(FILE='some directory specification',EXIST=ex) correctly tests
> > > for the existence of a directory with all my Windows compilers
> > > (g95,gfortran,lf95) except IVF. *Does anybody know the reason for this
> > > and what the standard says if anything?

>
> > > Al Greynoldswww.ruda.com

>
> > On Windows and Linux/UNIX/OSX a directory contains a special
> > file named ".". You might try:

>
> > INQUIRE( FILE = 'mydirectory/.', EXIST = exists )

>
> > Regards,

>
> > Arjen

>
> To be a little bit more portable, I also use an environment variable
> called for instance DELIMITER which is equals to "\" on Windows and
> "/" on unix :
>
> CHARACTER :: delimiter
> ...
> CALL get_environment_variable('DELIMITER',delimiter)
> INQUIRE(file='mydirectory'//delimiter//'.',EXIST=exist)- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


Of course , though I recently tried to see if a forward slash
would be acceptable on Windows (I used three different compilers)
and they all accepted both a / and a \ as a directory delimiter.

Regards,

Arjen
Reply With Quote
  #10  
Old 08-22-2008, 08:26 AM
fj
Guest
 
Default Re: Using INQUIRE to test if a directory exists

On 22 août, 14:07, Arjen Markus <arjen.mar...@wldelft.nl> wrote:
> On 22 aug, 13:38, fj <francois.j...@irsn.fr> wrote:
>
>
>
> > On 22 août, 08:51, Arjen Markus <arjen.mar...@wldelft.nl> wrote:

>
> > > On 21 aug, 23:18, Al Greynolds <awgreyno...@earthlink.net> wrote:

>
> > > > INQUIRE(FILE='some directory specification',EXIST=ex) correctlytests
> > > > for the existence of a directory with all my Windows compilers
> > > > (g95,gfortran,lf95) except IVF. Does anybody know the reason for this
> > > > and what the standard says if anything?

>
> > > > Al Greynoldswww.ruda.com

>
> > > On Windows and Linux/UNIX/OSX a directory contains a special
> > > file named ".". You might try:

>
> > > INQUIRE( FILE = 'mydirectory/.', EXIST = exists )

>
> > > Regards,

>
> > > Arjen

>
> > To be a little bit more portable, I also use an environment variable
> > called for instance DELIMITER which is equals to "\" on Windows and
> > "/" on unix :

>
> > CHARACTER :: delimiter
> > ...
> > CALL get_environment_variable('DELIMITER',delimiter)
> > INQUIRE(file='mydirectory'//delimiter//'.',EXIST=exist)- Tekst uit oorspronkelijk bericht niet weergeven -

>
> > - Tekst uit oorspronkelijk bericht weergeven -

>
> Of course , though I recently tried to see if a forward slash
> would be acceptable on Windows (I used three different compilers)
> and they all accepted both a / and a \ as a directory delimiter.
>
> Regards,
>
> Arjen


Even a microsoft compiler ?
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:40 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.