Mega Code Archive

 
Categories / Delphi / Examples
 

Determine if a file resides on ntfs file system

Question:: I need to determine if a file is located on a NTFS formatted drive. There is no Windows API function for this. Answer:: Indeed the Windows API does not provide such a function. Besides attempting to use NTFS specific functionalities and checking whether are supported - thus assuming it could be NTFS, you can create a FileSystemObject and use scripting. The only downside of this attempt is that for security reasons scripting may be disabled on some computers. uses ComObj; function IsNTFS(aFilename: string) : boolean; var fso, drv: OLEvariant; begin { IsNTFS } IsNTFS := False; fso := CreateOLEObject('Scripting.FileSystemObject'); drv := fso.GetDrive(fso.GetDriveName(aFilename)); IsNTFS := drv.FileSystem='NTFS' end; { IsNTFS } // example if IsNTFS('f:\letter.doc') then ShowMessage('File resides on NTFS File System')