Thank you both! :) These different ways of doing the same thing in Julia
are quite useful (and funny! :))

Best,

Charles

On 29 October 2015 at 18:29, Stefan Karpinski <ste...@karpinski.org> wrote:

> You can also use do-block syntax to make it a little easer to read:
>
> files = filter!(readdir(folder)) do fname
>     splitext(fname)[2] == "txt" && filesize(fname) >= minsize
> end
>
>
> Using the splitext function avoids the somewhat unlikely corner case of
> having a hidden file whose entire name is ".txt" which should probably not
> be considered to have the extension ".txt" even though it does technically
> end with that string.
>
> On Thu, Oct 29, 2015 at 11:53 AM, Yichao Yu <yyc1...@gmail.com> wrote:
>
>> On Thu, Oct 29, 2015 at 11:41 AM, Charles Novaes de Santana
>> <charles.sant...@gmail.com> wrote:
>> > Thanks! stat is great!! :)
>> >
>> > My R-biased programming can solve the problem by using the following
>> code:
>> >
>> > minsize=100
>> > folder=".";
>> > files =
>> >
>> filter!(r"\.txt$",readdir(folder))[map(filesize,filter!(r"\.txt$",readdir(folder))).>minsize]
>>
>> I don't think `readdir` necessarily garentee returning the files in
>> the same order every time you call it on all platforms. The simplest
>> improvement is just to call filter twice but you could also just do
>>
>> ```
>> filter!(fname->(endswith(fname, ".txt") && filesize(fname) > minsize),
>> readdir(folder))
>> ```
>>
>> Note that you don't need a regular expression for endswith...
>>
>> >
>> > It solves my problem. But I would appreciate if anyone has any other
>> > suggestion to do it in a Julia-style :)
>> >
>> > Thanks a lot!
>> >
>> > Best,
>> >
>> > Charles
>> >
>> > On 29 October 2015 at 16:25, Yichao Yu <yyc1...@gmail.com> wrote:
>> >>
>> >> stat[1] should have the info you need to write your own filter.
>> >>
>> >> [1]
>> >>
>> http://julia.readthedocs.org/en/latest/stdlib/file/?highlight=stat#Base.stat
>> >>
>> >> On Thu, Oct 29, 2015 at 11:22 AM, Charles Novaes de Santana
>> >> <charles.sant...@gmail.com> wrote:
>> >> > Hi julians,
>> >> >
>> >> > I am using readdir() and filter!() to list files in a folder that
>> match
>> >> > a
>> >> > given pattern (lets' say, to list all .txt files).
>> >> >
>> >> > Now I would like to filter the files according to their sizes. I only
>> >> > want
>> >> > to list non-empty files within a folder, so my first shot is to list
>> >> > files
>> >> > which sizes are higher than zero bytes.
>> >> >
>> >> > Some days ago there was a thread about listing the last modified
>> file,
>> >> > that
>> >> > used map() and mtime(). Do you know something similar to list files
>> by
>> >> > size?
>> >> >
>> >> > Thanks for any tip!
>> >> >
>> >> > Best,
>> >> >
>> >> > Charles
>> >> >
>> >> > --
>> >> > Um axé! :)
>> >> >
>> >> > --
>> >> > Charles Novaes de Santana, PhD
>> >> > http://www.imedea.uib-csic.es/~charles
>> >
>> >
>> >
>> >
>> > --
>> > Um axé! :)
>> >
>> > --
>> > Charles Novaes de Santana, PhD
>> > http://www.imedea.uib-csic.es/~charles
>>
>
>


-- 
Um axé! :)

--
Charles Novaes de Santana, PhD
http://www.imedea.uib-csic.es/~charles

Reply via email to