Create a new folder in Project Explorer
1. pe_mkdir folder:="subfolder"; // Creates a subfolder named "subfolder" under the currently active folder in Project Explorer.
2. pe_mkdir folder:="sub" path:= strPath$; // Creates a subfolder named "sub" under the currently active folder in Project Explorer and output full path in atrPath$ variable.
Please refer to the page for additional option switches when accessing the x-function from script
Input
string
The name of the new folder to be created. Depending on the value of the chk variable, if the name already exists, it will either add a number to end of new folder or it will not create the folder.
int
If set to 0 and folder already exists, it will create a new folder with number added to the end of the name. If set to 1 and folder already exists, it does not create a new folder.
If set to 1, make the newly created folder the active one in Project Explorer.
Output
The name of string variable (e.g. strPath$) to hold the full path to the newly-created folder (or existing folder) when the X-Function returns.
This X-Function is used to create a new folder in the Project Explorer for the current Origin project.
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. pe_cd path:="/"; // 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()) continue; // 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. string strFolderPath$; 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. string strBookPath$; 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$)"; }
pe_dir pe_cd pe_path pe_move