Opening multiple files???
Opening multiple files???
(OP)
I am trying to open multiple files, 1 at a time, and pull data. I am not having any success. I can read the data from a file by hardcoding the file name, but I have been unable to read all the files in a directory until no more files exist. Can anyone advise me a path I should take??
RE: Opening multiple files???
You can open a file by hardcoding in the name or placing a name into a character variable. However.... the Fortran standard does not specify a way to read specific filenames on a given operating system. This is largely because every operating system is different. The concept of a file or a directory or a folder is not the same on all systems. In fact.... basic fortran does not know what a directory is. And of course, a file is defined specifically by the operating system you are working with. However, different compilers may provide you a means of obtaining such data ( though, these features are not standardized ). You'll have to read through your compilers documentation to learn how to do such things.
Alternatively... you can ( from within your fortran code ) run another external program that will give you the data you need. You could possibly have this other program write out file names to another temporary file. Then, of course, you could open up that file and read the names you want.
In the end... it all depends on which compiler you are using.
Dan
www.dtware.com
RE: Opening multiple files???
You are correct is assuming I don't know the names of the files. I guess I can force the downstream user to specify at least a standard file name with just integer increments at the end of the filename...but that might be limiting to them. I appreciate your help and all the help I have received from this site.
THANKS...
RE: Opening multiple files???
dir name.ext>tmp.dir
program_name
The first line puts directory into tmp.dir, before running
progran_name.
<nbucska@pcperipherals.com>
RE: Opening multiple files???
Microsoft ( with all it's power and budget ) is very inconsistent!!! In each version of Windows... it has the DIR command work slightly differently. The command that Nbucksa shows will create a data file. The problem is that the format in the data file won't necessarily be simple. Each version of Windows does it differently. Also, any individual can easily tweak their computer to alter the format to their liking. Then... there's the long name / short name stuff. Also... rarely ( if ever ) does the DIR command insert a period, '.' , between the main name and extension for a file.
Thus... you the programmer will have to go to some trouble to write code to parse through the ASCII file and decide what all the valid filenames are. Though this is very possible... it isn't necessarily easy and you will need logic to handle all of the different possible formats that this file may be written in. I've done this type of thing before for my "quick and dirty" work. But... I wouldn't want to do it for a client that expects things to work easily for them every time.
Dan
www.dtware.com
RE: Opening multiple files???
http://www.microsoft.com/isapi/redir.dll?prd=ie&pver=5.0&ar=IStart
If you haven't done any work with making API calls from Fortran, you may be able to find a package that contains the calls already packaged for you.
RE: Opening multiple files???
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/file_management_functions.asp