Issue when doing if a list contains str from a list: return with wrong listI want to get a list of files that contain str from another list, but the return is empty. What did I do wrong? Can someone advise? Below is my script.
filelist = Files In Directory( path );
//filelist={"123_123_1_acdr.csv", "234_113_100_rqtfgy.csv", "53_1243_12_qqwed.csv", "6_12378_23_rty.csv"}
lst1 = {"234_113_100", "53_1243_12"};
lst2 = {};
For( i = 1, i <= N Items( filelist ), i++,
If( Contains( lst1, filelist[i] ),
Insert Into( lst2, filelist[i] )
)
);
Print( lst2 );
the expected output of lst2 ={"234_113_100_rqtfgy.csv", "53_1243_12_qqwed.csv"} however, the output lst2 is empty.
ScriptingRe: Issue when doing if a list contains str from a list: return with wrong listif a contains is used to search through a list, it will look for only complete matches. Searching through a string, one can check for partial matches.
//filelist = Files In Directory( path );
filelist = {"123_123_1_acdr.csv", "234_113_100_rqtfgy.csv", "53_1243_12_qqwed.csv",
"6_12378_23_rty.csv"};
lst1 = {"234_113_100", "53_1243_12"};
lst2 = {};
For( i = 1, i <= N Items( filelist ), i++,
For( k = 1, k <= N Items( lst1 ), k++,
If( Contains( filelist[i], lst1[k] ),
Insert Into( lst2, filelist[i] )
)
)
);
Print( lst2 );