Choose Language Hide Translation Bar
Level II

execute the function after comparing the filename

I'm trying to open a folder and scan the files and then run different functions with different files. I have done this so far but looks like once it hits the function, the file goes into infinite loop but doesn't do this if i have 1 print statement. The part of the function that goes into infinite loop works well when used solely without the hassle of picking a directory and opening a file. Can anyone please point out what could be causing the infinite loop when it worked just by itself.

myfunc = function({dt,mypath},{Dedault Local},
		col_list = dt << get column names( string );
		new_list = {};
		For( i = N Items( col_list ), i > 0, i--, //For loop to create an array of the different column strings
		If( Regex( col_list[i], "<some regex>") == col_list[i],
			Insert Into( new_list, col_list[i] ), //Insert Into(new_list,col_list[i]), 
			Remove From( col_list, i ); //If the string is not what we are looking for remove it from the array
mypath = Pick Directory ( "Select a directory." );
files = Files In Directory(mypath);
MY_FILES = files;
FOR(i=1, i <= N items(files), i++,
	if(Ends with(files[i],"_myfile.csv"),
		dt = Open(mypath || files[i]);
		dname = dt << Get Name;
				Contains( dname, "_myfile" ) > 0, myfunc(dt,mypath),
				"File is wrong"
			);	,

Level II

Re: execute the function after comparing the filename

Never mind, I think I've found the issue. For the function, I misspelled default as dedault. After fixing this, it works like a charm.
Article Labels

    There are no labels assigned to this post.