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
 Findfiles regex?

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
cgoerner Posted - 05/04/2022 : 07:49:26 AM
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!
4   L A T E S T    R E P L I E S    (Newest First)
cgoerner Posted - 05/10/2022 : 05:25:56 AM
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!
YimingChen Posted - 05/04/2022 : 3:58:52 PM
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
YimingChen Posted - 05/04/2022 : 2:46:07 PM
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
YimingChen Posted - 05/04/2022 : 10:33:11 AM
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

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