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
 Origin Forum
 import every nth file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Adamantan

6 Posts

Posted - 06/18/2024 :  04:20:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hey,
I have a large data set consisting of 3000 IR spectra in 3000 csv files that I would like to import. However, it would be impractical to import every single spectrum first and then delete the unwanted ones. How can I simply import, say, every 10th file without changing the original dataset?

Best regards,
Michael

Origin Ver. and Service Release: 2022b (64bit) 9.9.5.167
Operating System: Win10

YimingChen

1594 Posts

Posted - 06/18/2024 :  09:01:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can select multiple csv files in Windows Explorer, and drag them into Origin workspace to import.

James
Go to Top of Page

aplotnikov

Germany
160 Posts

Posted - 06/19/2024 :  04:58:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Import every n-th file:

int n=10;
string strDataPath$="X:\\AAA\\BBB\\";
findFiles path:=strDataPath$ ext:="csv" addpath:=1;
for(int iFileBeg = 1; iFileBeg < fname.GetNumTokens(CRLF); iFileBeg++) {
	int iFile;
	loop(iFile, 1, n-1) {
		fname.Replace(fname.GetToken(iFileBeg+1, CRLF)$ + "%(CRLF)", "");
	}
}
impASC;


If you have sequentially numbered files, you should combine the file names (including the data path) into the fname$-string in a loop:
int n=10;
int nFiles=20;
int iFile;
string strDataPath$="X:\\AAA\\BBB\\";
string strPrefix$="%(strDataPath$)spec_";
string strSuffix$="_xyz";
fname$="";
loop(iFile, 0, nFiles-1) {
	fname$ = fname$ + "%(strPrefix$)$(iFile*n+1, #4)%(strSuffix$).csv%(CRLF)";
}
impASC;


Use your own values for n, nFiles, strDataPath$, strPrefix$, strSuffix$ as well as the format of the sequential number. Tune the import options if necessary (see the impASC-X-Function documentation).

Edited by - aplotnikov on 06/19/2024 07:35:46 AM
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