K1200 Posted February 25, 2012 Posted February 25, 2012 I'm populating a value list from a field containing all the file names in a directory (hundreds of values). I need to filter it to only show files with a .txt or .TXT extension. I can do it using a loop in a script, but I'm hoping someone can point out a simple calculation technique. BTW, I've looked at a couple of functions on BrianDunning.com and found them too involved for this simple case. Others may eventually look at my code! Plus, I'd generally like to know how to filter fields for other reasons. Thanks for any help.
Raybaudi Posted February 25, 2012 Posted February 25, 2012 hundreds of values in a field ( 1 record ) or a value for each record ?
K1200 Posted February 25, 2012 Author Posted February 25, 2012 Hundreds of file names in a single field ... each one a value ... as returned by a plug-in's list folder function.
Raybaudi Posted February 25, 2012 Posted February 25, 2012 Using CustomList ( )* by Agnes Barouh, the calculation will be as simple as: CustomList ( 1 ; ValueCount ( text ) ; "If ( Right ( GetValue ( text ; [n] ) ; 4 ) = ".txt" ; GetValue ( text ; [n] ) )" ) * http://www.briandunning.com/cf/868 You could even try to use recursion with an unstored calculation field ( name it "result" ), looping with itself. Let([ T = yourTextField ; $i_InnerRecursion = $i_InnerRecursion + 1 ]; Case( Right ( GetValue ( T ; $i_InnerRecursion ) ; 4 ) = ".txt" and $i_InnerRecursion ≤ ValueCount ( T ) ; List ( GetValue ( T ; $i_InnerRecursion ) ; result ) ; $i_InnerRecursion ≤ ValueCount ( T ) ; result ; Let ( $i_InnerRecursion = "" ; "" ) ) )
comment Posted February 25, 2012 Posted February 25, 2012 How about a non-recursive one? FilterValues ( listOfFiles ; Substitute ( listOfFiles & ¶ ; [ ".txt" & ¶ ; "§" ] ; [ ".TXT" & ¶ ; "∆" ] ; [ ¶ ; "±¶" ] ; [ "§" ; ".txt" & ¶ ] ; [ "∆" ; ".TXT" & ¶ ] ) ) 1
LaRetta Posted February 26, 2012 Posted February 26, 2012 Now this rivals your Tower of Hanoi calculation and your laminated calculation as well. Absolute genius, watching the switch work through it. Is there any reason (other than clarity) that you listed it as ".TXT" & ¶ instead of "TXT¶" ?
comment Posted February 26, 2012 Posted February 26, 2012 Is there any reason (other than clarity) that you listed it as ".TXT" & ¶ instead of "TXT¶" ? Well, the idea is to generalize it into suffix & ¶ BTW, at least part of the credit goes to Agnes Barouh. Now this rivals your Tower of Hanoi calculation I have a Tower of Hanoi calculation?
imoree Posted February 26, 2012 Posted February 26, 2012 What are these icons? "§" "∆" & why are you using them in the calculation? thanks -i
comment Posted February 26, 2012 Posted February 26, 2012 They are characters assumed not to be used in listOfFiles.
imoree Posted February 26, 2012 Posted February 26, 2012 They are characters assumed not to be used in listOfFiles. thanks
Raybaudi Posted February 26, 2012 Posted February 26, 2012 How about a non-recursive one? Ahh, the power of FilterValues ( ) ! Well done.
LaRetta Posted February 26, 2012 Posted February 26, 2012 I have a Tower of Hanoi calculation? Well that is what I named your calculation where you first used §§ within Substitute() to play switch-a-roo with the values in this way. Your formula reminded me of Tower of Hanoi http://www.cut-the-k...nce/hanoi.shtml which I had first learned of from a great post here http://attic.fmforum...earch/1/#187899. Unfortunately, I could not find that original post where you first presented it and I sure tried. I believe it was around 2007. If you didn't have a billion posts on all the forums it would be easier but please continue making it difficult for us to keep up with your work. You would think I would remember the exact calculation of yours but it was not the formula that mattered in that instance but rather the power of using Substitute() to re-work values in such a pretty, recursive fashion. Tower of Hanoi is pretty cool. I miss Søren. He always added so much flavor (and sometimes heat, LOL) to a discussion.
Vaughan Posted February 26, 2012 Posted February 26, 2012 I miss Søren. He always added so much flavor (and sometimes heat, LOL) to a discussion. Yes. It was from reading his posts that I developed an enthusiasm for cyrptology. He certainly had a way with words. :)
comment Posted February 27, 2012 Posted February 27, 2012 Your formula reminded me of Tower of Hanoi I see - but the Tower of Hanoi is something much more complex. This is just 'cover the furniture while I spray-paint'.
steigrafx Posted February 27, 2012 Posted February 27, 2012 LaRetta, I believe your original "Tower of Hanoi" post is here: http://filemakertoday.com/com/showthread.php/9606-concatenated-list-substitution-and-for-final-comma "Thanks, Michael. What a pretty switch-a-roo! I'm naming your calc Tower of Hanoi."
LaRetta Posted February 27, 2012 Posted February 27, 2012 Then I'm mistaken because that wasn't the calc I was thinking of. But thank you for finding it anyway!! Well, I think many calculations are gorgeous and it's hard to find a favorite! :laugh2:
Recommended Posts
This topic is 4711 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now