Page 1 of 1

File MD5 Using ExamineDirectory

Posted: Sat Mar 08, 2008 11:01 am
by georgej
I am working on a small program to list all the files and their MD5 hash in a directory chosen by the user. I have a small procedure (based on the Examine Directory example given in the help file) to list the file name and MD5 in a List Icon gadget.

The file names are being listed, but the MD5 is not being shown for all files. When I select my own My Documents folder (approximately 40 files) for example, only two MD5 hashes are listed alongside the corresponding file names. Other directories with many more files in them list the file names but no MD5 at all.

Another part of the program processes individually selected files and this is works fine. The name and MD5 are displayed in the list.

I have tried various combinations of obtaining the files names and MD5 using the Examine Directory example and searched the forum without success. Is there something else that I need to do or check?

Code: Select all

Procedure ListDirectory()
  If ExamineDirectory(0,DirectoryToList,"*.*")  
    While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
        FileName.s = DirectoryEntryName(0)
        MD5U.s = UCase(MD5FileFingerprint(FileName))
        AddGadgetItem(#ListIcon_MD5, -1, FileName +Chr(10)+ MD5U)
      EndIf
    Wend
    FinishDirectory(0)
  EndIf

Posted: Sat Mar 08, 2008 11:36 am
by Trond
FileName.s will only contain ... guess what ... the filename! Not the path. If the current directory happens to be somewhere else, MD5FileFingerprint() will fail, as it looks in the current directory when not given a path.

Posted: Sat Mar 08, 2008 12:22 pm
by georgej
Thank you Trond. I will amend my code.

George

Edit: I have changed the code to...

Code: Select all

MD5U.s = UCase(MD5FileFingerprint((DirectoryToList + FileName)))
It works fine. Thanks!