View Full Version : How do you obtain the directory contents in Fortran.NET?
R. T. (Fortran Man)
02-04-2005, 08:19 PM
Fortran.net does not support the SYSTEM function used to execute another program. I used to use it to obtain the contents of a directory:
call system("dir > current.dir")
How do you do this in Fortran.NET?
Lahey Support
02-04-2005, 08:22 PM
When performing OS tasks like this in .NET you should use the .NET Framework. For this case you'll want to use the DirectoryInfo Class. I've included a short example below that prints the contents of the directory c:\temp. The DirectoryInfo class provides many methods to obtain very specific information about a file or directory. See DirectoryInfo in the .NET Framework section of the online documentation for more information.
program main
USE System
USE System%IO
TYPE(String), POINTER :: PathName
TYPE(DirectoryInfo), POINTER :: DirInfo
TYPE(FileInfo), POINTER :: FiInfo(:)
TYPE(String), POINTER :: contents
character (len=50) :: pname
PathName => ustring("C:\temp")
allocate (DirInfo, source=DirectoryInfo(PathName))
FiInfo => DirInfo.GetFiles(ustring("*"))
j = size(FiInfo)
do i = 0, j - 1
PathName => FiInfo(i).FullName
pname = string(PathName)
print *,pname
end do
end program
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.