Get MetaData of files in XML string format

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Get MetaData of files in XML string format

Post by wilbert »

Code: Select all

ImportC "-framework CoreServices"
  CFDataGetLength(theData)
  CFPropertyListCreateData(alloc, propertyList, format, options, *error)
  CFStringCreateWithCString(alloc, cStr.p-utf8, encoding = $8000100)
  MDItemCopyAttributes(item, names)
  MDItemCopyAttributeNames(item)
  MDItemCreate(allocator, path)
EndImport

Procedure.s GetMetaData(FileName.s)
  Protected.i Path, MDItem, Names, Attributes, CFData
  Protected Result.s
  Path = CFStringCreateWithCString(0, FileName)
  MDItem = MDItemCreate(0, Path)
  If MDItem
    Names = MDItemCopyAttributeNames(MDItem)
    Attributes = MDItemCopyAttributes(MDItem, Names)
    CFData = CFPropertyListCreateData(0, Attributes, 100, 0, #Null)
    Result = PeekS(CFDataGetBytePtr_(CFData), CFDataGetLength(CFData), #PB_UTF8)
    CFRelease_(CFData)
    CFRelease_(Attributes)
    CFRelease_(Names)
    CFRelease_(MDItem)
  EndIf
  CFRelease_(Path)
  ProcedureReturn Result
EndProcedure

Debug GetMetaData("test.jpg")
Windows (x64)
Raspberry Pi OS (Arm64)