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
 FindFolders function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Francesco84

Italy
21 Posts

Posted - 03/19/2021 :  10:46:52 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. OriginPro 2021, Operating System: Windows 7

Goodmorning,
I Have a problem with the FindFolders function.

I have a folder, with other folders inside. Each of them contains a single Origin file. opj, which I want to work on.

This is may code:

pathfolder$ = %1 // Main folder
int number = 0; // Number of subfolders

findFolders path:=pathfolder$ addpath:=1 n:=number; // Find the subfolders

for (int i=1; i<=1number; i++) // For each subfolder
{
string fns;
findFiles path:=folder.GetToken(i, CRLF)$ ext:="*.opj" addpath:=1 fname:=fns;

string FileName$ = fns.GetToken(1,CRLF)$;

doc -s;
doc -d; // Close the previous file
doc -o %(FileName$); // Open the Origin file

/* Other operations */

save dij %(FileName$);
}

The first file opens successfully.The others don't, because folder.GetToken(i, CRLF)$ now is empty.
If I comment, the line doc -o %(FileName$), the problem disappers.

How can I solve?

Thank you,
Francesco












YimingChen

1668 Posts

Posted - 03/19/2021 :  2:05:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

This is because folder$ is a project variable by default, when you open a new project, it's deleted. One solution is to define it as session variable. Add a line of code at the beginning:
string folder$;

Check the page below on session/project variables.
https://www.originlab.com/doc/LabTalk/guide/Data-Types-and-vars#Scope_of_Variables

James

Edited by - YimingChen on 03/19/2021 2:06:13 PM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 03/20/2021 :  12:49:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I noticed a typo in your code

i<=1number

As James pointed out, this is indeed a very tricky issue, as the XF framework will create project variable if not found. To help others, I posted code below to make it clear.


dlgpath;//pick a path and result put to path$
pathfolder$ = path$; // Main folder
int number = 2; // Number of subfolders

string results$;//use declared session variable

findFolders folder:= results$ path:=pathfolder$ addpath:=1 n:=number; // Find the subfolders

for (int i=1; i<=number; i++) // For each subfolder
{
	string fld$ = results.GetToken(i, CRLF)$;
	string fns;
	findFiles path:=fld$ ext:="*.opj" addpath:=1 fname:=fns;

	string FileName$ = fns.GetToken(1,CRLF)$;
	if(FileName.IsEmpty())
		continue;
	doc -s;
	doc -d; // Close the previous file
	doc -o %(FileName$); // Open the Origin file
	type -v "proj: %X%G";
}



CP
Go to Top of Page

Francesco84

Italy
21 Posts

Posted - 03/22/2021 :  07:37:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you all for the helpful answers

Francesco
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