Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
1 View

Apparent limitation on GetOpenFileName

I need to get a character array containing all of the filenames in a selected directory. Normally I use the windows function GOFN, around which I have built a wrapper for inclusion in my Fortran. Has always worked fine, but I now have a project where there are about 7,000 files in the directory. GOFN chokes if I try to select more than a hundred or so files, i.e. the statement

ierr = GetOpenFileName (ofn)

returns 0 (error; normally returns 1).

Q1: Has anybody noticed anything like this before? Is it likely due to a problem in my ofn structure? The contents of that structure are vast and complicated and I'm not likely to debug it myself.

Q2: Surely there is a workaround involving standard Fortran. I am contemplating fooling with GETFILEINFOQQ (files, buffer, handle), as the documentation implies it may do what I need with suitable treatment of the handle control mechanism. But I don't want to go chasing too far out the wrong tree branch. Does anybody know of a simple straightforward way to do this using just Fortran?

Again: Given a directory path, I need to get an array of all of the contained filenames, and it needs to work up to at least 7,000 files.

0 Kudos
4 Replies
Highlighted
1 View

A quick google brought me to

A quick google brought me to this MSDN page:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646839(v=vs.85).aspx

I'd check your lpstrFile field, to make sure it's pointing to a large enough buffer.

                        --Lorri

0 Kudos
Highlighted
1 View

This would be the nMaxFile

This would be the nMaxFile argument. Allocate a large enough buffer and insert pointer into lpstrFile and set the buffer size into nMaxFile.

Jim Dempsey

0 Kudos
Highlighted
New Contributor I
1 View

Lorri and Jim, thank you both

Lorri and Jim, thank you both for pointing me in the right direction. The problem is solved.

However, for other reasons I am still curious how to get an array of the filenames in a given directory using only Fortran functions. Any ideas about that? As I stated originally I suspect that GETFILEINFOQQ will do it but I don't want to waste time if there is a better way.

0 Kudos
Highlighted
Valued Contributor II
1 View

Fortran has limited native

Fortran has limited native functionality for this (INQUIRE), file and directory attributes are operating system dependent so this is really the domain of OS specific tools e.g Windows API. GETFILEINFOQQ is an intel extension which will make use of API functions ( see https://msdn.microsoft.com/en-us/library/windows/desktop/aa365526(v=vs.85).aspx ) .

GETFILEINFOQQ is pretty simple to use , making your file list array is only a handful of lines of code.

0 Kudos