Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


How to get an Unique Identifier for a File or FolderFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 3.x (or higher)
Category:
Win API
Skill Level:
Scoring:
Last Update:
07/16/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet unique file folder identifier GetFileInformationByHandle
Times Scored:
4
Visits:
3413
Uploader: Gerald Koeder
Company:
Reference: N/A
 
Question/Problem/Abstract:
Everyone who creates a File/folder copy or move-function must check if a sourcefile/folder exists at the destination. But how can we proof that two files don't point to the same physical place? Windows 2000 and XP allows to mount any volume under a folder and so it's possible that the files at 'c:\data\*.*' are the same as under 'd:\*.*' for example.
Answer:



To get an unique ID from a File or Folder you can use the API-Function GetFileInformationByHandle respective the Infos got from those function. The combination of the FileIndex with the Serial-Number of the Volume identifies a File.
To check if two files points to the same physical place just compare the two UIDs got from the function below.

btw: the function also works for folders because it uses FILE_FLAG_BACKUP_SEMANTICS; But this Flag ONLY works on WinNT and higher.


{-----------------------------------------------------------------------------
  Procedure: GetUFID
  Arguments: Filename: String
  Result:    String
  Comments:  Generate a Unique File-Identifier based upon Fileindex and the
             VolumeSerialnumber. If Filename doesn't exists result = '';
-----------------------------------------------------------------------------}
Function GetUFID(Filename: String): String;
Var
  hFile      : tHandle;
  FileInfo   : BY_HANDLE_FILE_INFORMATION;
  HighOrder,
  LowOrder   : Int64;
Begin
  // Get Filehandle ... Warning: Works only under WinNT and higher !!!
  hFile := CreateFile(pChar(Filename), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
  If hFile <> INVALID_HANDLE_VALUE then
  Begin
    If (GetFileInformationByHandle(hFile, FileInfo) = True) then
    Begin
      // Specifies the high-order word of a unique identifier associated with the file/folder
      HighOrder := FileInfo.nFileIndexHigh;
      // Specifies the low-order word of a unique identifier associated with the
      // file. This identifier and the volume serial number uniquely identify a file/folder
      LowOrder  := FileInfo.nFileIndexLow;
      Result    := Format('[%s-%s-%s]', [IntToStr(FileInfo.dwVolumeSerialNumber), IntToStr(LowOrder), IntToStr(HighOrder)]);
    End
    Else Result := '';
  End
  else Result := '';
  CloseHandle(hFile); //Release Handle
End;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Handle of a Folder on Win9x
    Gerald Koeder (Jul 16 2002 10:27PM)

Hi,

If someone knows a way to get a valid folderhandle on Win9x plz drop me a line. thx!

kind regards,
Gerald
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
C.A. Longen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)