#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access #pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later Function QuickRenameWrapper() String this String withthis Variable overwrite = 0 Prompt this, "Replace this (insert: pre = prepend; suf = append): " Prompt withthis, "With this: " Prompt overwrite, "Keep original?", popup "No;Yes, try to copy item;Yes, copy and overwrite;" DoPrompt "Replace Part of the Name", this, withthis, overwrite if (V_Flag) return -1 endif String name = "" Make/free/T/N=0 selection Make/free/N=0 sortorder Variable index=0 do name = GetBrowserSelection(index) if (strlen(name) <= 0) break endif selection[numpnts(selection)] = {name} sortorder[numpnts(sortorder)] = {ItemsInList(name,":")} index+=1 while(1) Sort/R sortorder, selection String namelist wfprintf namelist, "%s;", selection QuickRename(this, namelist, withthis, copy=(overwrite-1)) End Function QuickRename(String this, String namelist, String withthis, [Variable copy]) Variable copyItem = 0 // copy: 0 = don't keep original; 1 = try copy but don't overwrite; 2 = copy and overwrite if(!ParamIsDefault(copy)) copyItem = copy endif Variable index for (index = 0; index < ItemsInList(namelist); index += 1) String NewName = "", OldName = "", infolder = "" Variable isWave = 1 String name = StringFromList(index,namelist) Wave/Z work = $name if (!WaveExists(work)) // is folder OldName = ParseFilePath(0, name, ":", 1, 0) infolder = ParseFilePath(1, name, ":", 1, 0) isWave = 0 else OldName = nameofwave(work) endif if (StringMatch(this,"pre") == 1) NewName = withthis+OldName elseif (StringMatch(this,"suf") == 1) NewName = OldName+withthis else NewName = ReplaceString(this,OldName,withthis) endif if (isWave) Wave/Z test = $(SelectString(strlen(infolder),"root:",infolder)+NewName) if (copyItem == 2) Duplicate/O $Name, $NewName elseif (copyItem == 1) if (WaveExists(test) == 0) Duplicate $Name, $NewName endif else if (WaveExists(test) == 0) Rename $Name, $NewName endif endif else NewName = PossiblyQuoteName(ReplaceString("'",NewName,"")) if (copyItem == 2) DuplicateDataFolder/O=3 $(infolder+OldName), $(infolder+NewName) elseif (copyItem == 1) DFREF testDir = $(infolder+NewName) if (DataFolderRefStatus(testDir) == 0) DuplicateDataFolder $(infolder+OldName), $(infolder+NewName) endif else KillDataFolder/Z $(infolder+NewName) DFREF testDir = $(infolder+NewName) if (DataFolderRefStatus(testDir) == 0) RenameDataFolder $(infolder+OldName), $(ReplaceString("'",NewName,"")) endif endif endif endfor End