File MD5 Using ExamineDirectory

Just starting out? Need help? Post your questions and find answers here.
georgej
User
User
Posts: 11
Joined: Wed Aug 17, 2005 5:21 pm

File MD5 Using ExamineDirectory

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
georgej
User
User
Posts: 11
Joined: Wed Aug 17, 2005 5:21 pm

Post 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!
Post Reply