Subscribe Bookmark RSS Feed

How to index files in a folder using a substr ?

uday_guntupalli

Community Trekker

Joined:

Sep 15, 2014

All,
   When I have a folder with multiple files , how can I find the indices - to access these files using a common substr ?

For E.g. :

          If my folder has Ex1.jmp , Ex2.jmp , Ex3.jmp , AB.jmp.AC.jmp - I want to be able to search by Ex and get {1,2,3} as my index to access these files  .

Files = Files In Directory(Folder);

FilesIndex = Contains(Files,"Ex");

The above is the piece of code I tried

Best
uday

Best
Uday
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

When the Contains function is used with a list, there needs to be an exact match to a value in a list. When the Contains function is used with a string, it looks for a partial string within the larger string.

What you need to do is have a For loop that looks at each string in the Files list. See example below.

Files = Files In Directory( Folder );

FilesIndex = {};

For( i = 1, i <= N Items( Files ), i++,

If( Contains( Files[i], "Ex" ),

Insert Into( FilesIndex, i )

)

);

Justin
1 REPLY
Solution

When the Contains function is used with a list, there needs to be an exact match to a value in a list. When the Contains function is used with a string, it looks for a partial string within the larger string.

What you need to do is have a For loop that looks at each string in the Files list. See example below.

Files = Files In Directory( Folder );

FilesIndex = {};

For( i = 1, i <= N Items( Files ), i++,

If( Contains( Files[i], "Ex" ),

Insert Into( FilesIndex, i )

)

);

Justin