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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 pe_mkdir(“SP“) only if folder “SP“ does not exist

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
drreaf Posted - 12/07/2009 : 06:40:33 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
drreaf Posted - 12/08/2009 : 08:47:13 AM
Great, Penn!

Thanks a lot, Rainer
Penn Posted - 12/08/2009 : 05:43:47 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000