Opening 2500 files at once

Hello Igor Community,
I'm currently importing data from text files and turning it into images. I think that's a fairly common problem.
I wrote a procedure to open each of the files and import the data into multidimensional waves.
I'm using the Open Dialog for multiple files.

String message = "Select one or more files"
String outputPaths
String fileFilters = "Data Files (*.txt):.txt;"
fileFilters += "All Files:.*;"

Open /D /R /MULT=1 /F=fileFilters /M=message refNum
outputPaths = S_fileName

When I only have 900 files, it works fine, but when I try to open 2500 files, the open command seems to just abort and S_filename is empty.

I think maybe I'm hitting the limit for the number of files the dialog can handle, but I haven't seen a documented limit.

Is there a limit to the number of files? Is there something obvious that I'm missing?

Thank you.
900 files is a lot to have open at once. Even so, selecting that amount of files may be creating problems with the dialogue, in terms of string length.

Try these steps:
1) used IndexedFile to select all the files you're interested in (not interactive)
2) Iterate through that list to open each of the files in turn, perform your analysis and close the file.
mvlee wrote:

Is there a limit to the number of files? Is there something obvious that I'm missing?


The number of _simultaneously_ open files is usually limited [1]. In your case it might be easier to open the files one by one. So something along the lines of
function openFiles()
    variable i, refNum
    string filePath = "c:"
    string fileNames = "file1.txt;file2.txt"
    for(i=0; i < ItemsInList(fileNames);i+=1)
        Open/R refNum as filePath + StringFromList(i,fileNames)
        // handle file handles refNum
    endfor
End

should to the trick. You can also use NewPath to let the user select a directory and then read all files from this folder.
I recently did something similar to this, with 2000 text files. I used the IndexedFile command (as mentioned by Andyfaff) to go through all of the text files in 3 separate folders (three different time frames used different formats for the data). Just open a file, extract the information you want, close the file, and go to the next one. This iterative process blends nicely with indexedfile.

The post: http://www.igorexchange.com/node/1890 shows some code for this.
mvlee wrote:
Hello Igor Community,
I'm currently importing data from text files and turning it into images. I think that's a fairly common problem.
I wrote a procedure to open each of the files and import the data into multidimensional waves.
I'm using the Open Dialog for multiple files.

String message = "Select one or more files"
String outputPaths
String fileFilters = "Data Files (*.txt):.txt;"
fileFilters += "All Files:.*;"

Open /D /R /MULT=1 /F=fileFilters /M=message refNum
outputPaths = S_fileName

When I only have 900 files, it works fine, but when I try to open 2500 files, the open command seems to just abort and S_filename is empty.

I think maybe I'm hitting the limit for the number of files the dialog can handle, but I haven't seen a documented limit.

Is there a limit to the number of files? Is there something obvious that I'm missing?

Thank you.

I looked at the source code for the Open File dialog for multiple files on Windows. The Windows OS call we use requires that the buffer that receives the file names must be allocated before the call that puts up the Open File dialog. We allocate 50000 bytes for this buffer. That would leave room for 2500 20-character file names, except that it also has to store the path to the folder once. So if the path to the folder has, say, 100 characters, it would leave room for fewer than 2500 20-character file names. Naturally, it would be a different number depending on the number of characters in the individual file names. Oh, and there has to be room for a NULL byte between each name...

Note that this is not a limit on the number of simultaneously open files. This is a limit on the number of file names that can be returned from an Open File dialog with the /MULT flag. The allowed number of simultaneously open files is likely smaller.

As Thomas says, that's a lot of files. You might be better off with our older method of dealing with this sort of thing- if you can arranged for a single folder to contain all the files, and nothing but the files, then use IndexedDir to get file names. Use the NewPath command to get the path to a user-selected folder instead of requiring the selection of that many files in a dialog.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
thomas_braun wrote:

function openFiles()
    variable i, refNum
    string filePath = "c:"
    string fileNames = "file1.txt;file2.txt"
    for(i=0; i < ItemsInList(fileNames);i+=1)
        Open/R refNum as filePath + StringFromList(i,fileNames)
        // handle file handles refNum
    endfor
End
Don't forget to close the files:
function openFiles()
    variable i, refNum
    string filePath = "c:"
    string fileNames = "file1.txt;file2.txt"
    for(i=0; i < ItemsInList(fileNames);i+=1)
        Open/R refNum as filePath + StringFromList(i,fileNames)
        // handle file handles refNum
        Close refNum
    endfor
End

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:

Don't forget to close the files.

Yeep, missed that one. Not closing the file handle will not help in at all ...

bye,
Thomas