FAQ
Hi,

I think the object is self-descriptive.. I want to parse all the files
ending in .html in a directory; recursively.
Is it possible with ParseGlob ?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Christoph Hack at Jul 26, 2013 at 1:29 pm
    I don't know, but I would use filepath.Walk directly. For example:

    err := filepath.Walk(root, func(path string, info os.FileInfo, err error)
    error {
         if err != nil {
           return err; // you can also return nil here if you want to skip files
    and directories that can not be accessed
         }
         if info.IsDir() || !strings.HasSuffix(".html") {
           return nil // ignore directories and other files
         }
         err = parseFile(path)
         return err
    })

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Briche Arnaud at Jul 26, 2013 at 3:10 pm
    Thx Christoph, I followed your suggestion and ended up with a simple :

             template := template.New("template")

    filepath.Walk("src/main/templates", func(path string, info os.FileInfo, err
    error) error {
    if strings.HasSuffix(path, ".html") {
    template.ParseFiles(path)
    }

    return nil
    })

    Le vendredi 26 juillet 2013 15:29:52 UTC+2, Christoph Hack a écrit :
    I don't know, but I would use filepath.Walk directly. For example:

    err := filepath.Walk(root, func(path string, info os.FileInfo, err error)
    error {
    if err != nil {
    return err; // you can also return nil here if you want to skip
    files and directories that can not be accessed
    }
    if info.IsDir() || !strings.HasSuffix(".html") {
    return nil // ignore directories and other files
    }
    err = parseFile(path)
    return err
    })
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Shaban Naasso at Jul 29, 2013 at 9:48 am
    don't forget to return the error code from ParseFiles otherwise you will
    have a hard time finding errors in your templates :-)

    Am Freitag, 26. Juli 2013 17:10:29 UTC+2 schrieb briche...@gmail.com:
    Thx Christoph, I followed your suggestion and ended up with a simple :

    template := template.New("template")

    filepath.Walk("src/main/templates", func(path string, info os.FileInfo,
    err error) error {
    if strings.HasSuffix(path, ".html") {
    template.ParseFiles(path)
    }

    return nil
    })

    Le vendredi 26 juillet 2013 15:29:52 UTC+2, Christoph Hack a écrit :
    I don't know, but I would use filepath.Walk directly. For example:

    err := filepath.Walk(root, func(path string, info os.FileInfo, err error)
    error {
    if err != nil {
    return err; // you can also return nil here if you want to skip
    files and directories that can not be accessed
    }
    if info.IsDir() || !strings.HasSuffix(".html") {
    return nil // ignore directories and other files
    }
    err = parseFile(path)
    return err
    })
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Astromahi at Sep 17, 2014 at 12:31 pm
    Hi there,

    Maybe this help someone,

            const tp = "src"

    pattern := filepath.Join(tp, "*.html")
    tmpl := template.Must(template.ParseGlob(pattern))


    On Friday, 26 July 2013 17:16:47 UTC+5:30, briche...@gmail.com wrote:

    Hi,

    I think the object is self-descriptive.. I want to parse all the files
    ending in .html in a directory; recursively.
    Is it possible with ParseGlob ?
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Williamstevens at Apr 20, 2015 at 3:11 pm
    This only parses the html files in the existing directory, not
    subdirectories. This does not solve the question being asked. He is
    looking for a recursive version of this.
    On Wednesday, 17 September 2014 07:29:36 UTC-4, Mahendran Kathirvel wrote:

    Hi there,

    Maybe this help someone,

    const tp = "src"

    pattern := filepath.Join(tp, "*.html")
    tmpl := template.Must(template.ParseGlob(pattern))


    On Friday, 26 July 2013 17:16:47 UTC+5:30, briche...@gmail.com wrote:

    Hi,

    I think the object is self-descriptive.. I want to parse all the files
    ending in .html in a directory; recursively.
    Is it possible with ParseGlob ?
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 26, '13 at 11:46a
activeApr 20, '15 at 3:11p
posts6
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase