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
 how to loop over subfolders and all xls inside?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

akuhr

Germany
9 Posts

Posted - 03/06/2019 :  1:06:49 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2019, Win7Pro

Hello!

I want to give a path as parameter and then
let labtalk loop over all subfolder, in
every subfolder find all xls and doing
something with them.
The code I put here are only the booth mainloops
outside.
Inside the innerloop I do something with
imExcel and plotting. This is working.
First I have only the loop over the xls, which
was working and I now added the outer loop
looping over all subfolders.

But then it is not longer running, but
I dont find out, what is going wrong there?

How can I get it running?

string folder$;
string fname$;
string path$;
path$ = %1;

int number;
findfolders addpath:=1 n:=number;
for (int j=1; j<=number; j++)
{

   findFiles path:=folder.GetToken(j, CRLF)$ ext:="*.xls" addpath:=0;
   int nn = fname.GetNumTokens(CRLF);
   string fnnamesav$ = fname$;

   type "";
   #type "Pfad: $(path)";
   type "files found: $(nn)";
   type "";

   for (int i=1; i<=1; i++) // nn
   {
      string strFilename$ = fname.GetToken(i, CRLF)$;
      #type strfilename$;
   
      string name$ = strfilename$;

      int ibis = name.Len();
      int ibis = $(ibis) - 4;
      string fn$ = name.mid(1,$(ibis))$;

      type "opening $(i) with: %(fn$)";
      
      fname$ = fnnamesav$;

   }

}

Regards, Astrid

Edited by - akuhr on 03/06/2019 1:07:38 PM

yuki_wu

896 Posts

Posted - 03/07/2019 :  02:44:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Astrid,

You might forget to specify a string variable for the output string of folder when you call findFolders X-Function. Use like this:

int nFolders;
string strFolders;
findfolders path:="E:\MyFolder" addpath:=1 n:=nFolders folder:=strFolders;
for(int ii = 1; ii <=nFolders; ii++)
{
	strTemp$ = strFolders.GetToken(ii, CRLF)$;
	type -a strTemp$;
}


Hope it helps.

Regards,
Yuki

OriginLab

Edited by - yuki_wu on 03/07/2019 8:45:47 PM
Go to Top of Page

akuhr

Germany
9 Posts

Posted - 03/07/2019 :  06:53:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello!

Thanx a lot.
It is working very well.

Regards, Astrid
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