Re: [go-nuts] fs.Glob, fs.DirWalk, etc. does the pattern support complex regex

2022-11-04 Thread pat2...@gmail.com
Thanks to all who replied.
On Friday, November 4, 2022 at 8:47:51 AM UTC-4 Konstantin Khomoutov wrote:

> On Thu, Nov 03, 2022 at 01:20:16PM -0700, pat2...@gmail.com wrote:
>
> > This has to be a FAQ, but my google foo for searching it is not clear
> > The docs say: " The syntax of patterns is the same as in path.Match."
> > 
> > The pattern seems to implement only fairly simple search expressions.
> > 
> > I'd like to search for "./*.MP4", but of course to be platform 
> independant
> > I have to search for both upper and lower case "mp4" and "MP4" 
> > and maybe even allow "Mp4".
> > 
> > This is trivial in most regex, including go's regex
> > 
> > Can I do this with Glob or DirWalk? Or do I need to just
> > get the file names and manually apply the regex?
>
> The latter.
>
> But please note that I, for one, have not heard of any popular filesystem
> on a platform Go runs on which would support regexp matching when 
> traversing
> its entries, and fs.Glob is largely modelled after what Unix shells 
> implement.
> Hence basically if something like fs.Regexp were introduced, it would 
> anyway
> need to walk the hierarchy and apply the supplied regexp to each pathname 
> it
> visits.
>
> Please also note that using a regexp for what you're after looks like an
> overkill to me: a simple
>
> strings.EqualFold(filepath.Ext(fname), "mp4")
>
> in the callback function to fs.WalkDir wold convey the intent better, IMO.
>
> In any case, such a callback function to find a bunch of files matching 
> their
> extensions in a case-insensitive manner would clock at 10-15 lines, I'd 
> say.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/678cd07c-0c13-49fe-b5b5-d417351bbaf9n%40googlegroups.com.


Re: [go-nuts] fs.Glob, fs.DirWalk, etc. does the pattern support complex regex

2022-11-04 Thread Konstantin Khomoutov
On Thu, Nov 03, 2022 at 01:20:16PM -0700, pat2...@gmail.com wrote:

> This has to be a FAQ, but my google foo for searching it is not clear
> The docs say: " The syntax of patterns is the same as in path.Match."
> 
> The pattern seems to implement only fairly simple search expressions.
> 
> I'd like to search for "./*.MP4", but of course to be platform independant
> I have to search for both upper and lower case "mp4" and "MP4" 
> and maybe even allow "Mp4".
> 
> This is trivial in most regex, including go's regex
> 
> Can I do this with Glob or DirWalk? Or do I need to just
> get the file names and manually apply the regex?

The latter.

But please note that I, for one, have not heard of any popular filesystem
on a platform Go runs on which would support regexp matching when traversing
its entries, and fs.Glob is largely modelled after what Unix shells implement.
Hence basically if something like fs.Regexp were introduced, it would anyway
need to walk the hierarchy and apply the supplied regexp to each pathname it
visits.

Please also note that using a regexp for what you're after looks like an
overkill to me: a simple

  strings.EqualFold(filepath.Ext(fname), "mp4")

in the callback function to fs.WalkDir wold convey the intent better, IMO.

In any case, such a callback function to find a bunch of files matching their
extensions in a case-insensitive manner would clock at 10-15 lines, I'd say.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20221104124713.vlglr7fm6azkxpap%40carbon.


Re: [go-nuts] fs.Glob, fs.DirWalk, etc. does the pattern support complex regex

2022-11-03 Thread James
It makes the pattern a bit ugly, but you can definitely do it with
path.Match https://go.dev/play/p/zi6nh8Vj9LF

On Fri, 4 Nov 2022 at 09:20, pat2...@gmail.com  wrote:

> This has to be a FAQ, but my google foo for searching it is not clear
> The docs say: " The syntax of patterns is the same as in path.Match."
>
> The pattern seems to implement only fairly simple search expressions.
>
> I'd like to search for "./*.MP4", but of course to be platform independant
> I have to search for both upper and lower case "mp4" and "MP4"
> and maybe even allow "Mp4".
>
> This is trivial in most regex, including go's regex
>
> Can I do this with Glob or DirWalk? Or do I need to just
> get the file names and manually apply the regex?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/2d6cfad4-6a32-458a-89d1-f5546c80df90n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAFuMYUx%2B0t9i1ZtEmR6ncr_JTU20RHpqr9-tSOmFB828RoHGbw%40mail.gmail.com.


[go-nuts] fs.Glob, fs.DirWalk, etc. does the pattern support complex regex

2022-11-03 Thread pat2...@gmail.com
This has to be a FAQ, but my google foo for searching it is not clear
The docs say: " The syntax of patterns is the same as in path.Match."

The pattern seems to implement only fairly simple search expressions.

I'd like to search for "./*.MP4", but of course to be platform independant
I have to search for both upper and lower case "mp4" and "MP4" 
and maybe even allow "Mp4".

This is trivial in most regex, including go's regex

Can I do this with Glob or DirWalk? Or do I need to just
get the file names and manually apply the regex?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2d6cfad4-6a32-458a-89d1-f5546c80df90n%40googlegroups.com.