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
 Looping over files/folders in a directory
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AKazak

Russia
1205 Posts

Posted - 06/01/2022 :  03:51:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2022b (64-bit) SR1 9.9.5.167
Windows 7 Pro SP1 x64

Greetings!

I have a folder (directory) with several tens of OTPU templates that I want to plot in bath. I want my LT script to loop over OTPU files/folders in a directory and execute the plotting code.

How do I achieve this in LT?

Thank you.

---
Andrey

AKazak

Russia
1205 Posts

Posted - 06/01/2022 :  04:31:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The closest command I found so far is https://d2mvzyuse3lwjc.cloudfront.net/doc/en/LabTalk/ref/GetFileName-cmd :
getfile -m *.TXT; //select multiple file.
getfile -g 2; //Get the full path of the second file.
%A=;


However this calls the GUI dialog that I don't need.

---
Andrey
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/01/2022 :  1:33:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use the findFiles XF.
See
https://www.originlab.com/doc/X-Function/ref/findFiles

I tested with the following very simple code to list templates that begins with B



findfiles path:=system.path.program$ ext:="B*.otp*";
int nn = fname.GetNumTokens(CRLF);

for(int ii = 1; ii <= nn; ii++)
{
	string fn$ = fname.GetToken(ii, CRLF)$;
	fn$=;
}

Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/01/2022 :  1:44:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

You can use the findFiles XF.
See
https://www.originlab.com/doc/X-Function/ref/findFiles

I tested with the following very simple code to list templates that begins with B



findfiles path:=system.path.program$ ext:="B*.otp*";
int nn = fname.GetNumTokens(CRLF);

for(int ii = 1; ii <= nn; ii++)
{
	string fn$ = fname.GetToken(ii, CRLF)$;
	fn$=;
}





Got it!
This exactly what I need.
Thanks.

---
Andrey
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/01/2022 :  2:07:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Any ideas on looping over subdirectories in the target directory?

---
Andrey
Go to Top of Page

minimax

357 Posts

Posted - 06/02/2022 :  01:47:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
recursive:=1

In general you can run "XFName -h" to see some brief description of its variables without going to help page.
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/02/2022 :  04:09:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by minimax

recursive:=1

In general you can run "XFName -h" to see some brief description of its variables without going to help page.



Got it!
Thanks for the hint.

---
Andrey
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