A forced NewDataFolder to handle complex paths
pokeeffe
// forceNewDataFolder( destPath )
// string destPath relative or absolute path of directory to create
//
// Returns a DFREF which can be used to switching or referring to
//
Function/DF forceNewDataFolder( destPath )
string destPath
variable i
string folder = ""
string up = ""
DFREF sav0 = GetDataFolderDFR()
DFREF out
for (i=0; i<ItemsInList(destPath, ":"); i+=1) // for each folder in path
// folder = PossiblyQuoteName(StringFromList(i, destPath, ":")) // extract from list, possibly quoting
folder = ReplaceString("'", StringFromList(i, destPath, ":"), "") // extract from list, quotes will screw up NewDatafolder
If ( !strlen(folder) ) // if blank entry
up += SelectString(i, "", ":") // include semicolon, except for first row
continue // skip remainder of loop
elseif (strlen(up)) // if not blank but was
up += ":" // grouped :'s lose the first ":" so replace it
up = up[0, min(strlen(up), ItemsInList(GetDataFolder(1), ":"))-1] // remove :'s which refer upwards of root
SetDataFolder $up // switch up levels
endif
If (cmpstr(folder,"root")) // if folder isn't "root"
NewDataFolder/O/S $folder // create/switch to
else // but if it is
SetDataFolder root: // start in root, don't try to make it
endif
up = "" // clear up before next loop
endfor
out = GetDataFolderDFR() // capture current location to DFREF first
SetDataFolder sav0 // then return user to prev folder
return out // and hand back the DFREF
end
// string destPath relative or absolute path of directory to create
//
// Returns a DFREF which can be used to switching or referring to
//
Function/DF forceNewDataFolder( destPath )
string destPath
variable i
string folder = ""
string up = ""
DFREF sav0 = GetDataFolderDFR()
DFREF out
for (i=0; i<ItemsInList(destPath, ":"); i+=1) // for each folder in path
// folder = PossiblyQuoteName(StringFromList(i, destPath, ":")) // extract from list, possibly quoting
folder = ReplaceString("'", StringFromList(i, destPath, ":"), "") // extract from list, quotes will screw up NewDatafolder
If ( !strlen(folder) ) // if blank entry
up += SelectString(i, "", ":") // include semicolon, except for first row
continue // skip remainder of loop
elseif (strlen(up)) // if not blank but was
up += ":" // grouped :'s lose the first ":" so replace it
up = up[0, min(strlen(up), ItemsInList(GetDataFolder(1), ":"))-1] // remove :'s which refer upwards of root
SetDataFolder $up // switch up levels
endif
If (cmpstr(folder,"root")) // if folder isn't "root"
NewDataFolder/O/S $folder // create/switch to
else // but if it is
SetDataFolder root: // start in root, don't try to make it
endif
up = "" // clear up before next loop
endfor
out = GetDataFolderDFR() // capture current location to DFREF first
SetDataFolder sav0 // then return user to prev folder
return out // and hand back the DFREF
end
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More