Prev: Different answer when running cell second time?
Next: Part specification... is neither an integer nor a
From: Charles J. Koehler on 12 May 2010 07:34 Hello, I've been stumped on this for awhile. I read in a list of filenames from a directory, using wildcards to capture all the files I want to process. However, a few files make it into the list that I don't want. I these files have extra string of characters, that I should be able to remove using a regular expression and the appropriate Mathematica function. Any thoughts? Best Regards, Chuck Koehler
From: Nasser M. Abbasi on 13 May 2010 07:24 "Charles J. Koehler" <ckoehler5(a)wi.rr.com> wrote in message news:hse3or$379$1(a)smc.vnet.net... > > I read in a list of filenames from a directory, using wildcards to capture > all the files I want to process. However, a few files make it into the > list > that I don't want. I these files have extra string of characters, that I > should be able to remove using a regular expression and the appropriate > Mathematica function. Any thoughts? > Maybe use RegularExpression? assume you want to pick only the files with some extension, you can use: In[75]:= list = {"abc1.txt", "abc2.txt", "abc3.foo"}; Select[StringCases[list, RegularExpression[".*\\.txt"]],Length[#1] > 0 & ] Out[76]= {{abc1.txt}, {abc2.txt}} do help on RegularExpression for more examples. You can build an RE to do any filtering you want. Once you got the RE correct, then the rest is easy. --Nasser
From: Bill Rowe on 13 May 2010 07:23 On 5/12/10 at 7:35 AM, ckoehler5(a)wi.rr.com (Charles J. Koehler) wrote: >I read in a list of filenames from a directory, using wildcards to >capture all the files I want to process. However, a few files make >it into the list that I don't want. I these files have extra string >of characters, that I should be able to remove using a regular >expression and the appropriate Mathematica function. Any thoughts? You can likely do what you want with a combination of Cases, StringMathchQ and RegularExpression. But in order for me to be any more specific, you need to provide more details.
From: Albert Retey on 13 May 2010 07:23 Hi, > I've been stumped on this for awhile. > > > > I read in a list of filenames from a directory, using wildcards to capture > all the files I want to process. However, a few files make it into the list > that I don't want. I these files have extra string of characters, that I > should be able to remove using a regular expression and the appropriate > Mathematica function. Any thoughts? that should be easy enough with StringCases. See the documentation for details. In recent versions you can use RegularExpression or StringExpression in the first argument of FileNames directly, too... hth, albert
From: dr DanW on 13 May 2010 07:24
Something along the lines of Select[ list, Not(a)StringMatchQ[#, RegularExpression["^a.*"]] &] Insert regex of your choice. Enjoy, Daniel |