Origin Ver. and Service Release (Select Help-->About Origin): 2018b
Operating System: Windows 10
Hello,
I have a group of folders with the same subfolder structure. My code loops through all folders, and then through subfolders to import all .txt files from the last one.
The thing is, one of the folders does not have that subfolder structure (it will, eventually, but data has not been collected yet). I assumed it would simply skip it, but it does not. It shows an Invalid file path! error and stops.
I tried adding an if(exist (FolderString$)) command before importing, so that it would check whether the folder existed and only import the files if it did, but to no avail. Help guide (https://www.originlab.com/doc/LabTalk/ref/Exist-func) considers the use of strings, but not the use of paths, so I guess it will not work if the string is associated to a path. It does speak of specific folders, but only those within the origin file.
Below you can find the code I'm using, with the if(exist) command marked in red.
string strPath$ = %X%G;
path$= strPath$;
findFolders;
string froot$ = folder$;
int n = froot.GetNumTokens(CRLF);
for(int ii = 1; ii <=n; ii++)
{
//Folder creation
string TempFol$ = froot.GetToken(ii, CRLF)$;
string TempOven$ = TempFol.GetToken(2," ")$;
pe_mkdir folder:=TempOven$ cd:=1;
//Importing path
string TempPath$ = strPath$ + "\" + TempFol$;
path$ = TempPath$;
findFolders; // Find all folders
string fTemp$ = folder$;
int nn = fTemp.GetNumTokens(CRLF);
//Importing
for(int jj = 1; jj <=nn; jj++)
{
string dscFol$ = fTemp.GetToken(jj, CRLF)$;
newbook;
string RawData$ = page.name$;
string dscPath$ = TempPath$ + "\" + dscFol$;
path$ = dscPath$;
findFolders;
string fdsc$ = folder$;
int nnn = fdsc.GetNumTokens(CRLF);
for(int kk = 1; kk <=nnn; kk++)
{
string ZnFol$ = fdsc.GetToken(kk, CRLF)$;
string ZnPath$ = dscPath$ + "\" + ZnFol$ + "\Analysis\Atomic";
if(exist(ZnPath$))
{
path$ = ZnPath$;
findfiles ext:="txt";
int nnnn = fname.GetNumTokens(CRLF);
impasc fname$
Options.FirstMode:=4
Options.Mode:=4
Options.Sparklines:=2
Options.Headers.CountHeaderLines:=1
Options.Headers.MainHeaderLines:=0
Options.Headers.SubHeaderLines:=1
Options.Headers.LongName:=1
Options.Names.AutoNames:=0
Options.Names.FNameToColComm:=1
Options.Names.FNameToSht:=1
Options.Names.FNameToBk:=0 es
Options.Names.FPathToComm:=0
Options.FileStruct.NumSep:=1
Options.FileStruct.Delimiter:=3;
}
}
}
}
It works smoothly until it gets to the folder with the missing subfolder structure, where I get the same Invalid file path! error. I also tried creating the same subfolder structure in Windows explorer (with no files), but it eventually propmpted me to select them manually.
Am I applying the wrong command, or applying it in a wrong manner?
Also, is there any standard nomenclature for int function? Because that "nnnnn" thing is very, very ugly. I thought of n-m-o-p..., but I don't know if any of those subsequent letters is associated to the system, just like some string registers are.
Thank you.