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
 If (exist) for paths
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Clairekun

Germany
175 Posts

Posted - 08/07/2020 :  12:52:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2018b
Operating System: Windows 10

Hello,

I have a group of folders with the same subfolder structure. My code loops through all folders, and then through subfolders to import all .txt files from the last one.

The thing is, one of the folders does not have that subfolder structure (it will, eventually, but data has not been collected yet). I assumed it would simply skip it, but it does not. It shows an Invalid file path! error and stops.

I tried adding an if(exist (FolderString$)) command before importing, so that it would check whether the folder existed and only import the files if it did, but to no avail. Help guide (https://www.originlab.com/doc/LabTalk/ref/Exist-func) considers the use of strings, but not the use of paths, so I guess it will not work if the string is associated to a path. It does speak of specific folders, but only those within the origin file.

Below you can find the code I'm using, with the if(exist) command marked in red.
string strPath$ = %X%G;	
path$= strPath$;	
findFolders; 	
string froot$ = folder$;	
int n = froot.GetNumTokens(CRLF);	
for(int ii = 1; ii <=n; ii++)	
{
	//Folder creation
	string TempFol$ = froot.GetToken(ii, CRLF)$;	
	string TempOven$ = TempFol.GetToken(2," ")$; 
	pe_mkdir folder:=TempOven$ cd:=1;

	//Importing path
	string TempPath$ = strPath$ + "\" + TempFol$;	
	path$ = TempPath$;
	findFolders; 	//  Find all folders 
	string fTemp$ = folder$;
	int nn = fTemp.GetNumTokens(CRLF); 	
	
	//Importing
	for(int jj = 1; jj <=nn; jj++)
	{		
		string dscFol$ = fTemp.GetToken(jj, CRLF)$;	
		newbook; 
		string RawData$ = page.name$;
		string dscPath$ = TempPath$ + "\" + dscFol$;
		path$ = dscPath$;
		findFolders;
		string fdsc$ = folder$;
		int nnn = fdsc.GetNumTokens(CRLF);
		for(int kk = 1; kk <=nnn; kk++) 	
		{
			string ZnFol$ = fdsc.GetToken(kk, CRLF)$; 
			string ZnPath$ = dscPath$ + "\" + ZnFol$ + "\Analysis\Atomic";
			if(exist(ZnPath$))
			{
			path$ = ZnPath$;
			findfiles ext:="txt";	
			int nnnn = fname.GetNumTokens(CRLF);	
			impasc fname$
			Options.FirstMode:=4	
			Options.Mode:=4 	     
			Options.Sparklines:=2 	
			Options.Headers.CountHeaderLines:=1	
			Options.Headers.MainHeaderLines:=0	
			Options.Headers.SubHeaderLines:=1	
			Options.Headers.LongName:=1	
			Options.Names.AutoNames:=0	
			Options.Names.FNameToColComm:=1	  
			Options.Names.FNameToSht:=1	
			Options.Names.FNameToBk:=0 es 
			Options.Names.FPathToComm:=0	
			Options.FileStruct.NumSep:=1	
			Options.FileStruct.Delimiter:=3;
			}
		}
	}
}


It works smoothly until it gets to the folder with the missing subfolder structure, where I get the same Invalid file path! error. I also tried creating the same subfolder structure in Windows explorer (with no files), but it eventually propmpted me to select them manually.

Am I applying the wrong command, or applying it in a wrong manner?

Also, is there any standard nomenclature for int function? Because that "nnnnn" thing is very, very ugly. I thought of n-m-o-p..., but I don't know if any of those subsequent letters is associated to the system, just like some string registers are.

Thank you.

cpyang

USA
1406 Posts

Posted - 08/07/2020 :  2:53:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
if you have a string variable, then just use isPath(), like

if(str.Ispath())


See

https://www.originlab.com/doc/LabTalk/ref/String-obj#IsPath


CP
Go to Top of Page

Clairekun

Germany
175 Posts

Posted - 08/07/2020 :  3:38:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That was it!!

Thank you, it's working now!
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