Load most recent files in a directory

In an effort to automate a process in IGOR it would be nice to call a function and have it load waves from the most recent files in a directory. Is this something that can be done? I call 2 files, shown below. IT would be nice if I didn't have to go to the directory each time to do this.
    LoadWave/A/O/J/D/W/K=0/V={","," $",0,0}/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40} E:PTI Data:"20180302.130515_PTI.txt"
    LoadWave/A/O/J/D/W/K=0/V={","," $",0,0}/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40} E:PTI Data:"20180302.130516_Housekeeping.txt"

Thanks for the help.

ssmith
ssmith911 wrote:
In an effort to automate a process in IGOR it would be nice to call a function and have it load waves from the most recent files in a directory. Is this something that can be done? I call 2 files, shown below. IT would be nice if I didn't have to go to the directory each time to do this.
    LoadWave/A/O/J/D/W/K=0/V={","," $",0,0}/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40} E:PTI Data:"20180302.130515_PTI.txt"
    LoadWave/A/O/J/D/W/K=0/V={","," $",0,0}/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40} E:PTI Data:"20180302.130516_Housekeeping.txt"

Thanks for the help.

ssmith


You need to add the /P flag to these commands to do this. If you specify a path using NewPath you can then use that path with the /P flag. There's several file loaders in code snippets to draw some inspiration but you could have something like:

    NewPath/O/Q/M="Please find disk folder" diskFolder
    if (V_flag!=0)
        DoAlert 0, "Disk folder error"
        Return -1
    endif

and then you can use /P=diskFolder to load your files with LoadWave.
Your sample commands are not right. E:PTI Data:"20180302.130515_PTI.txt" is not a valid parameter. I will assume that you mean "E:PTI Data:20180302.130515_PTI.txt".

According to your example, you are trying to load using a fill path, "E:PTI Data:20180302.130515_PTI.txt". This should load without presenting a dialog. If it does present a dialog, that means that your full path in not correct. The same goes for "E:PTI Data:20180302.130516_Housekeeping.txt".

You should not need it in this case because you have a full path for both files. But in the general case of loading two files in the same directory whose file names are known but whose directory is not known, you can use the S_path output from the first LoadWave to form the parameter for the second LoadWave. For example:
LoadWave/J "FirstFile.txt"  // Displays an Open File dialog
if (V_flag != 0)   // The first load succeeded?
  String filePath = S_path + "SecondFile.txt"  // Generate full path
  LoadWave/J filePath
endif


See the help for LoadWave for a discussion of the S_path output variable.

sjr51's technique of using a symbolic path would also work. To learn about symbolic paths, execute:
DisplayHelpTopic "Symbolic Paths"

    LoadWave/A/O/J/D/W/K=0/V={","," $",0,0}/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40} "E:PTI Data:20180302.130515_PTI.txt"
    LoadWave/A/O/J/D/W/K=0/V={","," $",0,0}/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40} "E:PTI Data:20180302.130516_Housekeeping.txt"

Correct, this does not present a dialog. The filename is generated using using date and time. So the path is known but the filename is not. So I want to load the most recent *PTI.txt and the *Housekeeping.txt files in the E:PTI Data: directory. Thanks for the help

ssmith911
Quote:
So I want to load the most recent *PTI.txt and the *Housekeeping.txt files in the E:PTI Data: directory.


This could be done with a fair amount of work. You would have to get a list of all ".txt" files, using IndexedFile. You would then have to get the modification date for each file, using GetFileFolderInfo. To start, see the DemoIndexedFile example function in the help for IndexedFile.

For another approach, choose File->Example Experiments->Programming->Watch Folder.