MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Hash function

  • To: mathgroup at
  • Subject: [mg97527] Re: Hash function
  • From: Bill Rowe <readnews at>
  • Date: Sat, 14 Mar 2009 18:14:52 -0500 (EST)

On 3/14/09 at 5:41 AM, Ignacio.Plazeta at (Ignacio Plazeta)

>I bet I'm wrong in a childish way but I'm incapable to overcome the

>Why does the following code return discrepant values when processing
>two identical file ( CRTL + C , CRTL + V ) placed in two different
>folders ? Of course, I'm looking on only the Hash part of the out,
>being obviously the folder related part.

>Warmest regards. Ignacio

>fileIdentifier[myFile_]:=Module[{ tmp , folderPos },
>folderPos = StringPosition[myFile,"\\"]//Flatten//Max;

The key issue here is you want to use FileHash not Hash for
working with files. Additionally, your code can be made platform
independent and more robust by making more use of built in
functions. That is:

fileID[filename_] :=
  Module[{dirName = DirectoryName@filename},
   {FileByteCount[filename], FileHash[filename, "SHA512"],
     FileDate@filename, {"Year", "Month", "Day", "Hour", "Minute",
      "Second"}], StringDrop[dirName, -1],
    StringDrop[filename, StringLength@dirName]}]

  accomplishes the same thing as your code without the bug and
without need to know what character is used as a path name separator.

  • Prev by Date: Re: Comparing Corresponding Columns of Two Matrices
  • Next by Date: Weird NMinimize behaviour
  • Previous by thread: Re: Hash function
  • Next by thread: Re: Hash function