
Multiple file importing

Hello folks,
I realise this general issue may have been covered in the past but I will persist. I am using Igor 7.08. I don't usually write Igor code so I used ChatGPT to help me write a script to import 100-odd files with identical formats and headers in one go, including to append the filename to the start of the header, and to skip 8 of the 17 columns. AI removed the skip column part, telling me it was not supported by my version (is that right?), so I ended up with the code below. It compiles ok, however when I implement it in the command line an error message appears with 'Invalid folder path. Check for typos or permissions'. The file path seems fine, and I have tried placing some example files in a folder in Documents as well as Desktop, but same result.
If anyone has some ideas, I'd be keen to learn more.
Regards
Function ADMLoad()
// Register the Mac folder path (must end in colon)
NewPath/O/Q MyDataPath
PathInfo MyDataPath
if (V_flag != 0)
Abort "Invalid folder path. Check for typos or permissions."
endif
Variable fileIndex = 0
String fileName, fullPath, baseName
String wavesBefore, wavesAfter, newWaves
Variable i, j
do
fileName = IndexedFile(MyDataPath, fileIndex, ".txt")
if (strlen(fileName) == 0)
break
endif
fullPath = S_path + fileName
Variable lastDot = strsearch(fileName, ".", -1)
if (lastDot > 0)
baseName = fileName[0, lastDot - 1]
else
baseName = fileName
endif
wavesBefore = WaveList("*", ";", "")
// Load all columns (Igor 7 doesn’t support column filtering here)
LoadWave/Q/G/H/J fullPath
wavesAfter = WaveList("*", ";", "")
newWaves = ""
for (j = 0; j < ItemsInList(wavesAfter); j += 1)
String testName = StringFromList(j, wavesAfter)
if (WhichListItem(testName, wavesBefore) < 0)
newWaves += testName + ";"
endif
endfor
for (i = 0; i < ItemsInList(newWaves); i += 1)
String oldName = StringFromList(i, newWaves)
String newName = baseName + "_" + oldName
Rename oldName, newName
endfor
fileIndex += 1
while (1)
End
July 18, 2025 at 02:52 pm - Permalink
The test of V_Flag is backwards. The documentation for PathInfo says:
So it should say "if (V_Flag) == 0)".
Regarding the comment "(Igor 7 doesn’t support column filtering here)", the LoadWave operation in Igor Pro 7 does support the /B flag which allows you to skip columns so the comment seems to be wrong.
If you post a couple of files I may be able to write a procedure for you. In that case, please explain further how you want to name the waves. A simple way it could be done is to use a name of the form <filename><columnname> where a given column has a given columnname and <filename> is used to distinguish the waves from one file from the waves from another. If you want to use this name format, let me know what name to use for each column.
July 18, 2025 at 04:45 pm - Permalink
Yeah, as Howard said, it would be best if you could post a few demo files together with a short description of what you want to get done exactly and we can help you to set up a loading routine. While it is impressive that ChatGPT was able to come up with Igor code at all, it is clear that this isn't any good. Most of the script could be removed by using a few specialized functions instead. Examples:
- IndexedFile() could be run with index = -1 to get a file list right away, avoiding this implicit while loop
- using ParseFilePath() to get the clean file name instead of cutting strings into parts via lastDot (also the code for getting lastDot is wrong)
- using S_waveNames from LoadWave, which avoids 'finding out' which waves (newWaves) were loaded
... etc.
July 19, 2025 at 05:52 am - Permalink
Thanks for the quick reply and for correcting that line of code.
Of the 17 columns of data in each file, I would only like columns 1,2,4,6,7,10,13,14 and 17 imported. The columns already have a header, which can be incorporated into the new wavename thus: <filename>_<columnname>. Later, I will simplify the original columnname part of the new name once the data are loaded. I presume I can use:
Rename oldName, newName
with a wildcard? e.g. Rename *_depth_for_growth, *_depth
3 example files attached.
Regards
July 19, 2025 at 06:34 am - Permalink
Here is a procedure that should work for you. I tested it in Igor Pro 7 and Igor Pro 9.
I started two write this to load waves with names like HD_023_CGR_GR0_000_depth_for_growth but that created wave names that are too long for Igor Pro 7 in which wave names are limited to 31 characters. (In Igor Pro 8 or later wave names can be up to 255 characters.) To work around this issue, I rewrote the code to create waves with names like depth_for_growth in data folders with names like HD_023_CGR_GR0_000. That is what this code does.
July 19, 2025 at 11:16 am - Permalink
I am attaching the two versions of the procedure file that I mentioned in the preceding post.
July 19, 2025 at 11:19 am - Permalink
Hi Howard, A quick update: everything is humming along nicely thanks to your help. There is one tedious task that I don't seem to be able to simplify by copying and pasting from/into the command line: Saving a stack of waves to a delimited .txt file. I have done it the slow way via the menu, but when I copy the code and paste it into the command line and edit it (to update the target columns for exporting), I get a file save error. Below is an example of a manual export, but if I copy and paste that into the command line and change VGR to CGR and alter the filename to HD_CGR_GR.txt, there's an error message. Any help would be greatly appreciated.
Regards, rnd
July 23, 2025 at 11:12 am - Permalink
What does the error message say?
July 23, 2025 at 04:58 pm - Permalink
Here's a screenshot:
July 23, 2025 at 11:28 pm - Permalink
Here's a screenshot, Harold.
July 24, 2025 at 12:54 am - Permalink
This error means that at least one of the waves you are trying to save is nonexistent in the current folder, so you need to check whether you have made a mistake there. I would recommend to write a small script which accumulates specific waves automatically for saving (i.e., constructs gWMSaveWaveListStr0). This should be not so difficult.
July 24, 2025 at 02:12 am - Permalink
OK, thanks for this advice. I will check the blog to see if there's already something out there that I can edit.
Regards
July 24, 2025 at 05:51 am - Permalink
Try it in small sections to narrow down which wave name is incorrect:
If that generates an error, break it down further.
Or use this function to test if the waves exist:
July 24, 2025 at 08:54 am - Permalink