×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Opening multiple files???

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???

The problem here appears to be that you may not be aware of the names of all the files in a directory.  Is that correct?

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???

(OP)
DanTex,
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???

Alternative: Make a xxxx.bat file
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???

NBucska's suggestion will definately work.   The only reason I didn't suggest that one is because it has some hidden "gotcha's" that will get you if you aren't aware of them.

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???

If you need to be more Win-version-independent, you could go the route of making Windows API calls to get the file names from the directory. Search the MSN web site for help on the various calls you need to make. A starting URL for you is:

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close