Get current Project Explorer path or path of specified window
1. string strPath$; pe_path page:=Book1 path:=strPath$ type:=0; // Puts Project Explorer path to Book1 into strPath$ string variable.
2. pe_path page:=myFolder type:=folder active:=1; // Changes active folder in Project Explorer to the subfolder "myFolder" if it exists.
This X-function is used to either get the full Project Explorer path to a window (graph, workbook etc) or to activate a subfolder of the current folder in Project Explorer.
The example below utilizes four related X-Functions to reorganize an Origin project by creating and moving workbooks of imported data into folders that are named after the file extension of the files that were imported into the workbooks. The X-Functions that are used include: pe_cd, pe_mkdir, pe_path, and pe_move. Also illustrated is using the LabTalk document command as well as the String::GetFileExt()$ method.
// Use pe_cd X-function to change Project Explorer folder to the root folder for the Project.
// Loop through every workbook in the project.
document -e W
// Get the imported file name from page info tree of workbook (if it exists).
string strFileName$ = page.info.system.import.filename$;
// If the workboox does not contain imported data, the go to next workbook in loop.
if (0 == strFileName.GetLength())
// Use the pe_mkdir X-Function to create a subfolder in the Project Explorer root folder named
// after the file extension of the imported file. Note, the X-Function is specified to check
// if the folder already exists before creating it.
// strFolderPath$ will contain the full path once the X-Function returns.
pe_mkdir folder:="Imported %(strFileName.GetFileExt()$) Files" chk:=1 cd:=0 path:=strFolderPath$;
// Now use the pe_path X-Function to get the full Project Explorer path to where the workbook currently resides.
// strBookPath$ will contain the full path once the X-Function returns.
pe_path page:="%(page.name$)" path:=strBookPath$ type:=0 active:=0;
// Check to see if the workbook is already in the newly-created (or existing) folder by comparing the two paths.
// If it is not, then use the pe_move X-Function to move the workbook into the folder from its current location.
if (strBookPath$ != strFolderPath$)
pe_move -sb move:="%(page.name$)" path:="%(strFolderPath$)";