Home > Archive > Fortran > August 2007 > directory listing
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| gokhalen@gmail.com 2007-08-28, 7:12 pm |
| Hello:
Is there a way to obtain a list of files having a specified extension
using Fortran /Intel Fortran 9.1?
Thanks,
-Nachiket
| |
|
|
|
| On 28 ao=FBt, 22:23, gokha...@gmail.com wrote:
> Hello:
>
> Is there a way to obtain a list of files having a specified extension
> using Fortran /Intel Fortran 9.1?
>
> Thanks,
>
> -Nachiket
Using the specific Intel library is OK but a "more portable" way
consists in calling the routine SYSTEM available with most compilers.
But it remains necessary to test the operating system :
CHARACTER(10) :: extension=3D"f90"
CHARACTER(255) :: cfile
IF(os =3D=3D "unix") THEN
CALL system('ls -1 -p *.'//TRIM(extension)//'> list')
ELSE
CALL system('dir /b/ad/on *.'//TRIM(extension)//'> list')
ENDIF
Notice the options used respectively for the os dependent commands
"ls" and "dir" : they provide a very similar result ! After that, you
just have to open the file "list" and read each line using the format
"(A)" :
OPEN(15,file=3D"list") ! of course you can use another unit or even
select a free unit
! or even select a free unit (not used) but this
is another story
n=3D0
DO
READ(15,"(A)",END=3D10) cfile
write(*,*) TRIM(cfile)
ENDDO
10 CONTINUE
| |
| Arjen Markus 2007-08-29, 4:28 am |
| On 29 aug, 00:08, fj <francois.j...@irsn.fr> wrote:
> On 28 ao=FBt, 22:23, gokha...@gmail.com wrote:> Hello:
>
>
>
>
> Using the specific Intel library is OK but a "more portable" way
> consists in calling the routine SYSTEM available with most compilers.
> But it remains necessary to test the operating system :
>
> CHARACTER(10) :: extension=3D"f90"
> CHARACTER(255) :: cfile
>
> IF(os =3D=3D "unix") THEN
> CALL system('ls -1 -p *.'//TRIM(extension)//'> list')
> ELSE
> CALL system('dir /b/ad/on *.'//TRIM(extension)//'> list')
> ENDIF
>
> Notice the options used respectively for the os dependent commands
> "ls" and "dir" : they provide a very similar result ! After that, you
> just have to open the file "list" and read each line using the format
> "(A)" :
>
> OPEN(15,file=3D"list") ! of course you can use another unit or even
> select a free unit
> ! or even select a free unit (not used) but this
> is another story
> n=3D0
> DO
> READ(15,"(A)",END=3D10) cfile
> write(*,*) TRIM(cfile)
> ENDDO
> 10 CONTINUE
Small note: the option /ad means select only directories
Interesting idea though.
Regards,
Arjen
| |
|
|
>"fj" <francois.jacq@irsn.fr> wrote in message
>news:1188338937.234057.70310@y42g2000hsy.googlegroups.com...
On 28 août, 22:23, gokha...@gmail.com wrote:
>Using the specific Intel library is OK but a "more portable" way
>consists in calling the routine SYSTEM available with most compilers.
>But it remains necessary to test the operating system :
>
>CHARACTER(10) :: extension="f90"
>CHARACTER(255) :: cfile
>
>IF(os == "unix") THEN
> CALL system('ls -1 -p *.'//TRIM(extension)//'> list')
>ELSE
> CALL system('dir /b/ad/on *.'//TRIM(extension)//'> list')
>ENDIF
Or for those compilers where SYSTEM is a function not a subroutine
ivalue = system( ... )
Les
| |
|
| On 29 ao=FBt, 09:16, Arjen Markus <arjen.mar...@wldelft.nl> wrote:
> On 29 aug, 00:08, fj <francois.j...@irsn.fr> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
> Small note: the option /ad means select only directories
>
> Interesting idea though.
>
> Regards,
>
> Arjen
Right ... a bug again ! I copied an example dedicated to get sub-
directories only. Sorry
|
|
|
|
|