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
 FindFolders function

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
Francesco84 Posted - 03/19/2021 : 10:46:52 AM
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












3   L A T E S T    R E P L I E S    (Newest First)
Francesco84 Posted - 03/22/2021 : 07:37:25 AM
Thank you all for the helpful answers

Francesco
cpyang Posted - 03/20/2021 : 12:49:22 PM
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
YimingChen Posted - 03/19/2021 : 2:05:21 PM
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

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