FAQ
Hi,

I have this code:

https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

It simply read all files from one directory, calculates hash (sha256sum) of
each file, and read properties (date of modification, etc.) and puts in in
JSON output file.

Manually I put ',' after each codification of that information. The problem
is: how to avoid to put the last comma, and then have a JSON valid document.

Yeah, I know, it's not a pretty code, but I'm a newbee, I'm learning...
;-). If someone suggest an equivalent pretty code, it will be welcome...

Thanks in advance,
Xan

--
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

  • Chris dollin at Jul 15, 2013 at 10:42 am

    On 15 July 2013 10:49, Xan wrote:

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON valid
    document.
    My usual trick is to think of each element being /preceeded/ by a comma,
    which is left out for the /first/ element.

    , Chris

    --
    Chris "allusive" Dollin

    --
    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.
  • Dave Cheney at Jul 15, 2013 at 10:47 am
    Unrelated, you are opening and closing the output file for every
    source file you visit.
    On Mon, Jul 15, 2013 at 8:42 PM, chris dollin wrote:
    On 15 July 2013 10:49, Xan wrote:

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON valid
    document.
    My usual trick is to think of each element being /preceeded/ by a comma,
    which is left out for the /first/ element.

    , Chris

    --
    Chris "allusive" Dollin

    --
    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.
    --
    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.
  • Xan at Jul 15, 2013 at 3:16 pm
    How can I do that? Defining globally the outputfile?


    El dilluns 15 de juliol de 2013 12:47:24 UTC+2, Dave Cheney va escriure:
    Unrelated, you are opening and closing the output file for every
    source file you visit.
    On Mon, Jul 15, 2013 at 8:42 PM, chris dollin wrote:
    On 15 July 2013 10:49, Xan <xanc...@gmail.com <javascript:>> wrote:

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash
    (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts
    in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON
    valid
    document.
    My usual trick is to think of each element being /preceeded/ by a comma,
    which is left out for the /first/ element.

    , Chris

    --
    Chris "allusive" Dollin

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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.
  • Xan at Jul 15, 2013 at 3:22 pm
    This: https://github.com/quatrilio/find-duplicated-files/blob/2b703e260923f38d3593ca28942fa335176d52b1/walk.go

    says me:
    # command-line-arguments
    ./walk.go:81: undefined: f
    ./walk.go:87: undefined: f

    El dilluns 15 de juliol de 2013 12:47:24 UTC+2, Dave Cheney va escriure:
    Unrelated, you are opening and closing the output file for every
    source file you visit.
    On Mon, Jul 15, 2013 at 8:42 PM, chris dollin wrote:
    On 15 July 2013 10:49, Xan <xanc...@gmail.com <javascript:>> wrote:

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash
    (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts
    in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON
    valid
    document.
    My usual trick is to think of each element being /preceeded/ by a comma,
    which is left out for the /first/ element.

    , Chris

    --
    Chris "allusive" Dollin

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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.
  • Xan at Jul 15, 2013 at 3:15 pm
    Thanks,
    solved: https://github.com/quatrilio/find-duplicated-files/blob/c55d3687e2e35f94e013b2e0555a8737859a8c08/walk.go

    El dilluns 15 de juliol de 2013 12:42:23 UTC+2, chris dollin va escriure:
    On 15 July 2013 10:49, Xan <xanc...@gmail.com <javascript:>> wrote:

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON valid
    document.
    My usual trick is to think of each element being /preceeded/ by a comma,
    which is left out for the /first/ element.

    , Chris

    --
    Chris "allusive" Dollin
    --
    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.
  • Carlos Castillo at Jul 15, 2013 at 1:49 pm
    If you can generate a list of strings (eg: using append), you could use
    strings.Join(). Or if byte slices are your fancy:
    bytes.Join. http://golang.org/pkg/strings/#Join http://golang.org/pkg/bytes/#Join

    Alternatively, there is a json encoder in go. You just have to build a type
    that represents your final output, and fill it in during execution, and
    then write it out using the "encoding/json"
    package. http://blog.golang.org/json-and-go
    On Monday, July 15, 2013 2:49:03 AM UTC-7, Xan wrote:

    Hi,

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON valid
    document.

    Yeah, I know, it's not a pretty code, but I'm a newbee, I'm learning...
    ;-). If someone suggest an equivalent pretty code, it will be welcome...

    Thanks in advance,
    Xan
    --
    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.
  • Carlos Castillo at Jul 15, 2013 at 1:56 pm
    Sorry, didn't see that you were already using "encoding/json".

    You could still just make a []Message containing all the output data and
    write that out using "encoding/json"; you wouldn't have to worry about the
    commas, and you would only be writing to/opening the file once.
    On Monday, July 15, 2013 6:49:54 AM UTC-7, Carlos Castillo wrote:

    If you can generate a list of strings (eg: using append), you could use
    strings.Join(). Or if byte slices are your fancy: bytes.Join.
    http://golang.org/pkg/strings/#Join http://golang.org/pkg/bytes/#Join

    Alternatively, there is a json encoder in go. You just have to build a
    type that represents your final output, and fill it in during execution,
    and then write it out using the "encoding/json" package.
    http://blog.golang.org/json-and-go
    On Monday, July 15, 2013 2:49:03 AM UTC-7, Xan wrote:

    Hi,

    I have this code:

    https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go

    It simply read all files from one directory, calculates hash (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON valid
    document.

    Yeah, I know, it's not a pretty code, but I'm a newbee, I'm learning...
    ;-). If someone suggest an equivalent pretty code, it will be welcome...

    Thanks in advance,
    Xan
    --
    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.
  • Sol Toure at Jul 15, 2013 at 2:48 pm
    Or you could put the comma before the content after you ave written the
    first one. You just need one more variable to keep that state.

    On Mon, Jul 15, 2013 at 9:56 AM, Carlos Castillo wrote:

    Sorry, didn't see that you were already using "encoding/json".

    You could still just make a []Message containing all the output data and
    write that out using "encoding/json"; you wouldn't have to worry about the
    commas, and you would only be writing to/opening the file once.

    On Monday, July 15, 2013 6:49:54 AM UTC-7, Carlos Castillo wrote:

    If you can generate a list of strings (eg: using append), you could use
    strings.Join(). Or if byte slices are your fancy: bytes.Join.
    http://golang.org/**pkg/strings/#Join<http://golang.org/pkg/strings/#Join>
    http://**golang.org/pkg/bytes/#Join <http://golang.org/pkg/bytes/#Join>

    Alternatively, there is a json encoder in go. You just have to build a
    type that represents your final output, and fill it in during execution,
    and then write it out using the "encoding/json" package.
    http://blog.golang.**org/json-and-go <http://blog.golang.org/json-and-go>
    On Monday, July 15, 2013 2:49:03 AM UTC-7, Xan wrote:

    Hi,

    I have this code:

    https://github.com/quatrilio/**find-duplicated-files/blob/**
    master/walk.go<https://github.com/quatrilio/find-duplicated-files/blob/master/walk.go>

    It simply read all files from one directory, calculates hash (sha256sum)
    of each file, and read properties (date of modification, etc.) and puts in
    in JSON output file.

    Manually I put ',' after each codification of that information. The
    problem is: how to avoid to put the last comma, and then have a JSON valid
    document.

    Yeah, I know, it's not a pretty code, but I'm a newbee, I'm learning...
    ;-). If someone suggest an equivalent pretty code, it will be welcome...

    Thanks in advance,
    Xan
    --
    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.

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 15, '13 at 9:49a
activeJul 15, '13 at 3:22p
posts9
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase