Page 1 of 1
Destroying subsets by wildcard search?
Posted: Thu Feb 12, 2009 10:49 pm
by Thirsty Brick
I am trying to design a TM1 TI code method to delete subsets from a given dimension where not all of the subset name is specified.
Its not that I don't know all of the name, but that the name is generated in TI by a combination of multiple user-entered variables (up to 7) to make it unique and I would like to just pick one variable to use to delete a set of subsets rather than searching through all of the combinations to define the name, see if it exists and then delete it.
So, any ideas?...can I pass a partial name with a wildcard to SubsetDestroy()?
Re: Destroying subsets by wildcard search?
Posted: Thu Feb 12, 2009 11:53 pm
by nhavis
It might be best if you give an example - and indicate whether or not that will be the only case...
For example you might want to find "string1" anywhere inside "string2" or you might want to use a more complex regex.
Re: Destroying subsets by wildcard search?
Posted: Fri Feb 13, 2009 7:35 am
by ScottW
You have to pass a valid subset name to SubsetDestroy, but you could ...
1/ use WildCardFileSearch to return the subset file name
2/ substring the returned value to remove ".sub"
3/ then SubsetDestroy
Code: Select all
# what's the string we want to search for
pTempSubPrefix = 'YOUR_PREFIX_NAMING_CONVENTION_HERE';
# full path to where we want to look for subsets
vFileSearch = cServerPath | sDim | '}subs\' | pTempSubPrefix | '*.sub' ;
# find all subsets beginning with prefix if this dim folder exists
iContinue = 1;
vPriorFileName = '';
While( iContinue =1 ) ;
vZFile = WildcardFileSearch( vFileSearch, vPriorFileName );
IF( vZFile @<> '' );
# check for the subset file object & trim the .sub to delete
vSubset = SubSt( vZFile, 1, Long( vZFile ) - 4 );
IF( SubsetExists( sDim, vSubset ) = 1 );
SubsetDestroy( sDim, vSubset );
EndIF;
# look for next z subset after this one
vPriorFileName = vZFile;
Else;
# no more subset files beginning with prefix
iContinue = 0;
EndIF;
End;
Make sure to delete any temp views that the subsets are used in first, otherwise you won't be able to delete the subsets. (You can use the same technique for cleaning unwanted views.)