Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-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!

*Tek-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

Reading files inside many numbered folders

Reading files inside many numbered folders

Reading files inside many numbered folders


I have a number of folders labeled K00001 to K00100 in my scratch folder. Each folder contains a file called a.dat.

From my scratch folder, I would like to go into each folder, read the content of a.dat, save the necessary information to an array and then move on to the next folder.

I declared a CHARACTER as such:

CHARACTER(*), PARAMETER :: fileplace ="/home/vahid/scratch/K"

The I run a DO loop over the folders:

DO f=1,100
OPEN(unit=100,'(a,i5,a)') 'fileplace',f,'/a.dat'
read the file, etc.

The OPEN statement results in the following error:

error #5082: Syntax error, found IDENTIFIER 'FILEPLACE' when expecting one of: <END-OF-STATEMENT> ;
OPEN(unit=100,'(a,i5,a)') fileplace,f,/a.dat

Any suggestions as to how I can resolve this error would be a great help.

Thank you,


RE: Reading files inside many numbered folders

You need to create the filename in a buffer first


character(256):: filename
do f = 1, 100
   ! create the filename
   write(filename,'(a,i5,a)') fileplace, f, 'a.dat'
   ! open the file
   open(unit = 100, file=filename)
end do 

RE: Reading files inside many numbered folders

Thanks xwb. It worked. I just had to use i5.5 instead of i5 in the format statement to get the leading zeros.

Best wishes,


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 Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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

Close Box

Join Tek-Tips® Today!

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

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close