The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 pe_mkdir(SP) only if folder SP does not exist
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

drreaf

Germany
45 Posts

Posted - 12/07/2009 :  06:40:33 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release: OriginPro 7.5 SR6 and 8.0 SR6
Operating System: Windows XP Prof.

Sometimes I have to check whether a PE-subfolder (comprising a sub-project) SubProj does exist already. In this case I want to remove it by the Lab-Talk command pe_rmdir(SubProj) together with all its contents, before I begin a re-analysis of the sub-project which starts with pe_mkdir(SubProj).

If I execute an unconditional pe_rmdir(SubProj) I provoke an error message

Error!!! Can't remove subfolder SubProj !

which is a nuisance.

If I execute an unconditional pe_mkdir(SubProj) the automatic enumeration is more than a nuisance.

Any means to achieve my goal in LabTalk (e.g. if exist()??? )

Rainer

Dr. Rainer Facius, German Aerospace Center

Penn

China
644 Posts

Posted - 12/08/2009 :  05:43:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rainer,

Presently, there is no such a function for testing the existence of a subfolder in Project Explorer. However, you can write a function by using Origin C to do this.
Steps are below:

1. Click the Code Builder button on the standard toolbar to open the Coder Builder.
2. New a C File and add the following code in it.

// this function used to delete and create the specified subfolder in the active folder
void delete_and_create_subfolder_in_acitve_folder(string strFolder)
{
	Folder fld = Project.ActiveFolder(); // get active folder
	
	// call delete_and_create_subfolder() function
	delete_and_create_subfolder(strFolder, fld.GetPath());
}

// this function used to delete and create the specified subfolder in the root folder
void delete_and_create_subfolder(string strFolder, string strRootPath = "")
{
	// trim white space
	strFolder.TrimRight();
	strFolder.TrimLeft();
	
	Folder fld(strRootPath);  // get root folder path
	
	if(fld.IsValid())   // if root folder exist
	{
		foreach(Folder subfolder in fld.Subfolders)  // loop all subfolders
		{
			// if subfolder exist
			if(0 == subfolder.GetName().Compare(strFolder) )
			{
				// delete this subfolder
				fld.RemoveSubFolder(subfolder.GetName());					
			}
			else
			{			
				if( subfolder.Subfolders.Count() > 0 )  // search subfolder's subfolder
				{
					delete_and_create_subfolder(strFolder, subfolder.GetPath());
				}
			}
		}
		fld.AddSubfolder(strFolder);  // add a subfolder by the specified name
	}	
}

3. Click the Build button.
4. Return to Origin. If you want to delete then create a subfolder in the active folder, just type

delete_and_create_subfolder_in_acitve_folder("SubProj");

in command window.

We have submitted a tracker (tr#14817) to improve the exist() function, then you can use it to test the existence of a subfolder in Project Explorer.

Penn
OriginLab Technical Services
Go to Top of Page

drreaf

Germany
45 Posts

Posted - 12/08/2009 :  08:47:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Great, Penn!

Thanks a lot, Rainer
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000