Skip to content

Commit c918064

Browse files
authored
Merge pull request #2403 from AllenInstitute/bugfix/2403-speedup-get-all-files-recursively
GetAllFilesRecursivelyFromPath: Speed it up with custom extension
2 parents f1b6d33 + 2436f40 commit c918064

16 files changed

+675
-122
lines changed

Packages/Conversion/MIES_MassExperimentProcessing.ipf

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,16 @@ Function StartMultiExperimentProcessWrapper()
296296
outputFolder = S_Path
297297
ASSERT(V_flag, "Invalid path")
298298

299-
files = GetAllFilesRecursivelyFromPath("MultiExperimentInputFolder", extension = ".pxp")
299+
WAVE/Z files = GetAllFilesRecursivelyFromPath("MultiExperimentInputFolder", regex = "(?i)\.pxp$")
300300

301-
// 16: Case-insensitive alphanumeric sort that sorts wave0 and wave9 before wave10.
302-
// ...
303-
// 64: Ignore + and - in the alphanumeric sort so that "Text-09" sorts before "Text-10". Set options to 80 or 81.
304-
files = SortList(files, FILE_LIST_SEP, 80)
305-
306-
WAVE/Z/T inputPXPs = ListToTextWave(files, FILE_LIST_SEP)
301+
if(WaveExists(files))
302+
Sort/A=2 files, files
303+
else
304+
Make/FREE/T/N=0 files
305+
endif
307306

308307
jsonID = JSON_New()
309-
JSON_AddWave(jsonID, "/inputFiles", inputPXPs)
308+
JSON_AddWave(jsonID, "/inputFiles", files)
310309
JSON_AddString(jsonID, "/inputFolder", inputFolder)
311310
JSON_AddString(jsonID, "/outputFolder", outputFolder)
312311
JSON_AddVariable(jsonID, "/index", 0)

Packages/MIES/MIES_AnalysisBrowser.ipf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,19 +2649,24 @@ static Function AB_AddExperimentEntries(string win, WAVE/T entries)
26492649
symbPath = GetUniqueSymbolicPath()
26502650
NewPath/O/Q/Z $symbPath, entry
26512651
if(GetCheckBoxState(win, "check_load_pxp"))
2652-
pxpList = GetAllFilesRecursivelyFromPath(symbPath, extension = ".pxp")
2653-
uxpList = GetAllFilesRecursivelyFromPath(symbPath, extension = ".uxp")
2654-
else
2655-
pxpList = ""
2656-
uxpList = ""
2652+
WAVE/Z/T pxps = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.(pxp|uxp)$")
26572653
endif
26582654
if(GetCheckBoxState(win, "check_load_nwb"))
2659-
nwbList = GetAllFilesRecursivelyFromPath(symbPath, extension = ".nwb")
2660-
else
2661-
nwbList = ""
2655+
WAVE/Z/T nwbs = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.nwb$")
26622656
endif
26632657
KillPath/Z $symbPath
2664-
WAVE/T fileList = ListToTextWave(SortList(pxpList + uxpList + nwbList, FILE_LIST_SEP), FILE_LIST_SEP)
2658+
2659+
if(WaveExists(pxps) && WaveExists(nwbs))
2660+
Concatenate/NP=(ROWS)/FREE/T {nwbs, pxps}, fileList
2661+
elseif(WaveExists(pxps))
2662+
WAVE/T fileList = pxps
2663+
elseif(WaveExists(nwbs))
2664+
WAVE/T fileList = nwbs
2665+
else
2666+
break
2667+
endif
2668+
2669+
Sort fileList, fileList
26652670
elseif(FileExists(entry))
26662671
Make/FREE/T fileList = {entry}
26672672
else

Packages/MIES/MIES_CheckInstallation.ipf

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ static Function CHI_CheckITCXOPVersion(STRUCT CHI_InstallationState &state)
8282
End
8383

8484
/// @brief Search list for matches of item and print the results
85-
static Function CHI_CheckXOP(string &list, string item, string name, STRUCT CHI_InstallationState &state, [string expectedHash])
85+
static Function CHI_CheckXOP(WAVE/T list, string item, string name, STRUCT CHI_InstallationState &state, [string expectedHash])
8686

8787
variable numMatches, i, hashMatches
88-
string matches, fileVersion, filepath, existingHash, hashMsg
88+
string fileVersion, filepath, existingHash, hashMsg
8989

90-
matches = ListMatch(list, "*" + item, FILE_LIST_SEP)
91-
numMatches = ItemsInList(matches, FILE_LIST_SEP)
90+
WAVE/Z/T matches = GrepTextWave(list, "(?i)" + item)
91+
numMatches = WaveExists(matches) ? DimSize(matches, ROWS) : 0
9292

9393
if(numMatches > 1)
9494
if(CheckIfPathsRefIdenticalFiles(matches))
@@ -106,7 +106,7 @@ static Function CHI_CheckXOP(string &list, string item, string name, STRUCT CHI_
106106
state.numErrors += 1
107107
break
108108
case 1:
109-
filepath = StringFromList(0, matches, FILE_LIST_SEP)
109+
filepath = matches[0]
110110
fileVersion = GetFileVersion(filepath)
111111
if(ParamIsDefault(expectedHash))
112112
printf "%s: Found version %s (Nice!)\r", name, fileVersion
@@ -119,10 +119,10 @@ static Function CHI_CheckXOP(string &list, string item, string name, STRUCT CHI_
119119
endif
120120
break
121121
default:
122-
printf "%s: Found multiple versions in \"%s\" (Might create problems)\r", name, matches
122+
printf "%s: Found multiple versions in \"%s\" (Might create problems)\r", name, TextWaveToList(matches, ", ", trailSep = 0)
123123
printf "%s: Duplicates are:\r", name
124124
for(i = 0; i < numMatches; i += 1)
125-
filepath = StringFromList(i, matches, FILE_LIST_SEP)
125+
filepath = matches[i]
126126
fileVersion = GetFileVersion(filepath)
127127
if(ParamIsDefault(expectedHash))
128128
printf "%s: Found version %s\r", name, fileVersion
@@ -224,26 +224,32 @@ End
224224
Function CHI_CheckInstallation()
225225

226226
string symbPath, allFiles, path, extName, info, igorBuild
227-
string allFilesSystem, allFilesUser, listOfXOPs
228227
variable aslrEnabled, archBits, installedWithHW
229228

230229
symbPath = GetUniqueSymbolicPath()
231230
extName = GetIgorExtensionFolderName()
232231

233232
path = SpecialDirPath("Igor Pro User Files", 0, 0, 0) + extName
234233
NewPath/Q/O $symbPath, path
235-
allFilesUser = GetAllFilesRecursivelyFromPath(symbPath)
234+
WAVE/Z/T allFilesUser = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.xop$", resolveAliases = 1)
236235

237236
path = SpecialDirPath("Igor Application", 0, 0, 0) + extName
238237
NewPath/Q/O $symbPath, path
239-
allFilesSystem = GetAllFilesRecursivelyFromPath(symbPath)
238+
WAVE/Z/T allFilesSystem = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.xop$", resolveAliases = 1)
240239

241240
KillPath $symbPath
242241

243-
listOfXOPs = ListMatch(allFilesUser + FILE_LIST_SEP + allFilesSystem, "*.xop", FILE_LIST_SEP)
244-
WAVE/T list = ListToTextWave(listOfXOPs, FILE_LIST_SEP)
245-
WAVE/T listNoDups = GetUniqueEntries(list)
246-
listOfXOPs = TextWaveToList(listNoDups, FILE_LIST_SEP)
242+
if(WaveExists(allFilesUser) && WaveExists(allFilesSystem))
243+
Concatenate/T/FREE/NP=(ROWS) {allFilesUser, allFilesSystem}, listWithDuplicates
244+
elseif(WaveExists(allFilesUser))
245+
WAVE/T listWithDuplicates = allFilesUser
246+
elseif(WaveExists(allFilesSystem))
247+
WAVE/T listWithDuplicates = allFilesSystem
248+
else
249+
Make/FREE/N=0/T listWithDuplicates
250+
endif
251+
252+
WAVE/T listOfXOPs = GetUniqueEntries(listWithDuplicates)
247253

248254
STRUCT CHI_InstallationState state
249255
CHI_InitInstallationState(state)

Packages/MIES/MIES_Configuration.ipf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,25 +297,26 @@ End
297297
/// @brief Return a text wave with absolute paths to the JSON configuration files
298298
static Function/WAVE CONF_GetConfigFiles([string customIPath])
299299

300-
string settingsPath, fileList
300+
string settingsPath
301301

302302
if(ParamIsDefault(customIPath))
303303
settingsPath = CONF_GetSettingsPath(CONF_AUTO_LOADER_GLOBAL)
304304
else
305305
settingsPath = customIPath
306306
endif
307-
fileList = GetAllFilesRecursivelyFromPath(settingsPath, extension = ".json")
308307

309-
if(IsEmpty(fileList) && !ParamIsDefault(customIPath))
308+
WAVE/Z/T fileList = GetAllFilesRecursivelyFromPath(settingsPath, regex = "(?i)\.json$")
309+
310+
if(!WaveExists(fileList) && !ParamIsDefault(customIPath))
310311
settingsPath = CONF_GetSettingsPath(CONF_AUTO_LOADER_USER)
311-
fileList = GetAllFilesRecursivelyFromPath(settingsPath, extension = ".json")
312+
WAVE/Z/T fileList = GetAllFilesRecursivelyFromPath(settingsPath, regex = "(?i)\.json$")
312313
endif
313314

314-
if(IsEmpty(fileList))
315+
if(!WaveExists(fileList))
315316
return $""
316317
endif
317318

318-
return ListToTextWave(fileList, FILE_LIST_SEP)
319+
return fileList
319320
End
320321

321322
/// @brief Automatically loads all *.json files from MIES Settings folder and opens and restores the corresponding windows

Packages/MIES/MIES_DAEphys.ipf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4711,8 +4711,7 @@ End
47114711

47124712
static Function DAP_LoadBuiltinStimsets()
47134713

4714-
string symbPath, stimset, files, filename
4715-
variable i, numEntries
4714+
string symbPath, filename
47164715

47174716
symbPath = GetUniqueSymbolicPath()
47184717
NewPath/Q $symbPath, GetFolder(FunctionPath("")) + ":Stimsets"
@@ -4723,10 +4722,13 @@ static Function DAP_LoadBuiltinStimsets()
47234722
return NaN
47244723
endif
47254724

4726-
files = GetAllFilesRecursivelyFromPath(symbPath, extension = ".nwb")
4727-
numEntries = ItemsInList(files, FILE_LIST_SEP)
4728-
for(i = 0; i < numEntries; i += 1)
4729-
filename = StringFromList(i, files, FILE_LIST_SEP)
4725+
WAVE/Z/T files = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.nwb$")
4726+
4727+
if(!WaveExists(files))
4728+
return NaN
4729+
endif
4730+
4731+
for(filename : files)
47304732
NWB_LoadAllStimsets(filename = filename, overwrite = 1, loadOnlyBuiltins = 1)
47314733
endfor
47324734

Packages/MIES/MIES_DebugPanel.ipf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ End
7575

7676
static Function DP_FillDebugPanelWaves()
7777

78-
string symbPath, path, allProcFiles
78+
string symbPath, path
7979

8080
WAVE/T listWave = GetDebugPanelListWave()
8181
WAVE listSelWave = GetDebugPanelListSelWave()
@@ -84,15 +84,17 @@ static Function DP_FillDebugPanelWaves()
8484

8585
path = FunctionPath("") + "::"
8686
NewPath/Q/O $symbPath, path
87-
allProcFiles = GetAllFilesRecursivelyFromPath(symbPath, extension = ".ipf")
87+
WAVE/Z allProcFilesMIES = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.ipf$")
88+
ASSERT(WaveExists(allProcFilesMIES), "Expected some MIES procedure files")
8889

8990
path += ":IPNWB"
9091
NewPath/Q/O $symbPath, path
91-
allProcFiles = AddListItem(allProcFiles, GetAllFilesRecursivelyFromPath(symbPath, extension = ".ipf"), FILE_LIST_SEP)
92+
WAVE/Z allProcFilesIPNWB = GetAllFilesRecursivelyFromPath(symbPath, regex = "(?i)\.ipf$")
93+
ASSERT(WaveExists(allProcFilesIPNWB), "Expected some IPNWB procedure files")
9294

9395
KillPath $symbPath
9496

95-
WAVE/T list = ListToTextWave(allProcFiles, FILE_LIST_SEP)
97+
Concatenate/FREE/NP=(ROWS)/T {allProcFilesMIES, allProcFilesIPNWB}, list
9698
// remove path components
9799
list = GetFile(list[p])
98100
// remove non mies files

Packages/MIES/MIES_MiesUtilities_Uploads.ipf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,10 @@ Function UploadCrashDumps()
182182

183183
diagSymbPath = GetSymbolicPathForDiagnosticsDirectory()
184184

185-
WAVE/T files = ListTotextWave(GetAllFilesRecursivelyFromPath(diagSymbPath, extension = ".dmp"), FILE_LIST_SEP)
186-
WAVE/T logs = ListTotextWave(GetAllFilesRecursivelyFromPath(diagSymbPath, extension = ".txt"), FILE_LIST_SEP)
187-
numFiles = DimSize(files, ROWS)
188-
numLogs = DimSize(logs, ROWS)
185+
WAVE/Z/T files = GetAllFilesRecursivelyFromPath(diagSymbPath, regex = "(?i)\.dmp$")
186+
WAVE/Z/T logs = GetAllFilesRecursivelyFromPath(diagSymbPath, regex = "(?i)\.txt$")
189187

190-
if(!numFiles && !numLogs)
188+
if(!WaveExists(files) && !WaveExists(logs))
191189
return NaN
192190
endif
193191

0 commit comments

Comments
 (0)