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.
A quick google brought me to this MSDN page:
I'd check your lpstrFile field, to make sure it's pointing to a large enough buffer.
This would be the nMaxFile argument. Allocate a large enough buffer and insert pointer into lpstrFile and set the buffer size into nMaxFile.
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.
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.