How to uniquely/permanently identify a file

Hi,

I am writing a file management application in VB6. The way it works is that it scans a given directory, and then for each file found in that directory, my application asks certain info (File Description, Rating 1-5, Category, etc.), generates an identifier which is = filename.ext and then uses this identifier for all other operations such as copy, move, delete etc.

Now, the issue is that I need some definite/universal identifier for each file. Because, the filename may change over time, I will have to find some other "hash" or some other mechanism for a file which will keep it independent from rename, move, delete etc.

I believe, in unix there is an addressable identifer called inode for each file. Well anyway, I hope I have presented my problem well. Please share your thoughts about how to go about this problem, any code will also be helpful.

Thanks.
dosdemonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BurbbleCommented:
You could do something simple like calculate the CRC-32 of the file.

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=12638&lngWId=1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wraith821Commented:
use the following code to create a Global unique Identifier. Every number generated is unique worldwide.

Dim IDGen
set IDGen = CreateObject("Scriptlet.TypeLib")

Dim NewGUID as string
NewGUID = Replace(IDGEN.GUID,"{","")    'Get the GUID and remove the begining brace
NewGUID = Replace(NewGUID,"}","")       'Remove the Ending Brace
NewGUID = Replace(NewGUID,"-","")       'Remove the dashes
Robberbaron (robr)Commented:
You may be able to use the NTFS5 filesummary stream to attach extra info to each file.  NTFS5 (Win2000+) allows files to be made upof numerous streams. The best example is the Primary default stream and the FileSummary stream.

Select any file on Win2000/XP,  Right-click, Properties and you will see a Summary Tab.  It is generally empty but you can manually update it. eg Title, KEywords, Comments.  You can also create other User defined streams. For the latter, MS have released a DLL dfsofile.dll (search MSN) that you can add to a VB project.  I use this to tag PDF files created using AutoCad with some project info for later use in a document management system.

code based upon MS sample......
Option Explicit

Sub writeIDProps(curdoc As String, Optional txtProjectId As String = "", Optional txtTitle As String = "", Optional txtType As String = "", Optional txtStatus As String = "", Optional txtDrafted As String = "", Optional txtDesigned As String = "", Optional txtChecked As String = "", Optional txtApproved As String = "")

    ' Add Reference to:
    ' DS: OLE Document Properties 1.4 Object Library
       
    Dim oDocProp As DSOFile.OleDocumentProperties
   
    Set oDocProp = New DSOFile.OleDocumentProperties
   
    oDocProp.Open curdoc, False, dsoOptionOpenReadOnlyIfNoWriteAccess

    Dim oDocPrSumm As DSOFile.SummaryProperties
    Dim oDocPrCustom As DSOFile.CustomProperties
    Dim oDocProperty As DSOFile.CustomProperty
   
   
    Set oDocPrSumm = oDocProp.SummaryProperties
    Set oDocPrCustom = oDocProp.CustomProperties
   
    'MsgBox oDocPrSumm.Title & "!" & oDocPrSumm.Subject
    'Summary information fields you can change using a script include:
    'Author; Category; Comments; Company; Keywords; LastEditedBy;
    'Manager; Subject; and Title.
    'BUT ONLY FOR MSOffice docs!      MS comment!  
    'NO. only for docs with a stream created using explorer or some other method. eg Delphi

    'So use custom properties only
    'SetDSOCustomPropertyValue oDocProp, "ID_Project", "Test 1 2 3"
    'SetDSOCustomPropertyValue oDocProp, "ID_Subject ", Format(Rnd() * 50 + 200, "000")
   
    SetDSOCustomPropertyValue oDocProp, "ID_Project", txtProjectId
   
    SetDSOCustomPropertyValue oDocProp, "ID_Title", txtTitle
    SetDSOCustomPropertyValue oDocProp, "ID_DocType", txtType
    SetDSOCustomPropertyValue oDocProp, "ID_Status", txtStatus
   
    SetDSOCustomPropertyValue oDocProp, "ID_Drafted", txtDrafted
    SetDSOCustomPropertyValue oDocProp, "ID_Designed", txtDesigned
    SetDSOCustomPropertyValue oDocProp, "ID_Checked", txtChecked
    SetDSOCustomPropertyValue oDocProp, "ID_Approved", txtApproved
     
    If oDocProp.IsDirty Then
        oDocProp.Save
    End If
   
    Set oDocPrSumm = Nothing
    Set oDocPrCustom = Nothing
           
    oDocProp.Close False
   
    Set oDocProp = Nothing

End Sub

'works for me. Only problem is you cant see the Custom properties via explorer. I've written a Delphi program to just write to the Comments field of SummaryProperties, thereby creating the stream. Stream can then be updated via VB / DSOfile
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.