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

cgoerner

Germany
7 Posts

Posted - 05/04/2022 :  07:49:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2022 SR1 9.9.0.225
Operating System: Win10

Hi there!

I am trying to import several image files from a folder into Origin using the findfiles X-function. I used the example code here and it works well: https://www.originlab.com/doc/LabTalk/guide/Importing-Images#Import_Multiple_Images_to_Matrixbook .

Onto my problem: Not all of the images should be imported. There are about 200 images in each folder, and there is a new folder every day. Importing the images manually takes too long, this needs to be automated. The amount and order of the image files can slightly change. However the naming layout is always the same. Is there a way to select images with findfiles like with a regular expression?

In my case images with the substring "off" should not be selected, only images with "4" after "_" should be selected and a few other criteria.

Thank you in advance!

YimingChen

1666 Posts

Posted - 05/04/2022 :  10:33:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use string Match() function which supports wildcard. See the page below:
https://www.originlab.com/doc/en/LabTalk/ref/String-obj#Match

James
Go to Top of Page

YimingChen

1666 Posts

Posted - 05/04/2022 :  2:46:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Origin now supports running Python script. You can use regular expression in Python to filter the image files. Please select from menu
Connectivity:Open Untitled.py... and copy/paste the script below. Press F5 to execute.

from os import listdir
from os.path import isfile, join
import re
import originpro as op

mypath = op.path('e') + 'Samples\Image Processing and Analysis'
p = re.compile(r'myocyte\w*')
all_images = [f for f in listdir(mypath) if isfile(join(mypath, f)) and p.match(f) is not None]
for file in all_images:
    op.lt_exec(f'impimage fname:="{mypath}\{file}" orng:=<new>')


James

Edited by - YimingChen on 05/04/2022 2:46:56 PM
Go to Top of Page

YimingChen

1666 Posts

Posted - 05/04/2022 :  3:58:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is another solution. go to menu Connectivity:Open Default Python Functions... and add the Python script into the file:

from os import listdir
from os.path import isfile, join
import re

def getFileList(path):  
    '''S:s'''
    p = re.compile(r'myocyte\w*')
    all_images = [f for f in listdir(path) if isfile(join(path, f)) and p.match(f) is not None]
    return all_images


Then run the LT script below. It calls the Python function to fetch the list of file names to import.


Python.LTwd$="";
string path$ = system.path.program$+"Samples\Image Processing and Analysis";
Dataset -a sa = py.getFileList(path$);
for( int ii = 1 ; ii <= sa.GetSize() ; ii++ )
{
  string fname$= path$ + "\" + sa[ii]$;
  impimage orng:=<new>;  
} 


James

Edited by - YimingChen on 05/04/2022 5:19:32 PM
Go to Top of Page

cgoerner

Germany
7 Posts

Posted - 05/10/2022 :  05:25:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi James!

I was able to implement it using Match() for now.
The python approaches will be helpful in the future.

Thank you so much!
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