Categorize files using metadata or file attributes

RobDownUnder
RobDownUnder used Ask the Experts™
on
Categorize files that are in a single folder

    Is there a way to categorize files that are located within a single folder ?
    I am considering using the Comments field in the file's attributes to store the category(s)
    Say there is a single folder in the C drive, and I display all it's file names in a listbox.
    The files mainly would be  .jpg   .msg(outlook's)   .docx   .xlsx   .pdf
    Sometimes the user wishes to show all the files in the listbox.
    Some other times they wish to apply a filter to the list in the listbox.
    The filter would NOT be based on the extension, instead it would be based on some categories.
    The categories are related to their business, but let us say they are these -
    CAT1 CAT2 CAT3 CAT4 CAT5 CAT6 CAT7
    They wish to mark some of the files with a category, and sometimes a file would have multiple categories.
    They do not wish to change the File names.
    Can the categories be stored in the file attributes (perhaps in the Comments field) (is that called metadata ?)
    One file might have just Cat2
    Another file might have Cat2 and Cat3 and Cat6 (stored thus in the comments field "Cat2 Cat3 Cat6")
    When they apply the filter (say Cat2), only files with Cat2 in the comments field, would show in the listbox.
    If they apply a filter of Cat 6, only one file appears in the Listbox
    If they apply a filter of Cat 2, both files will appear in the Listbox

    Can the Comments field be used reliably, in that manner,  from VB6 ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:

Author

Commented:
Thanks for assisting akimark,
I am using XP (where my VB6 IDE is installed).
In my 'Googling' I recall that MetaData is not fully supported in W7 onwards, so that might effect DSOfile.dll (mind you it might effect everything I try).
However even in XP the DSOfile.dll appears to have a problem.
I download the VB6 sample from your link, and installed it into my XP PC
I tried it with a XLS and a JPG file, and it worked.
However I tried it with a PDF, and got this error -
Error: The document is not an OLE file, and does not support extended document properties.
The person who will use the program, uses PDF a lot, so that stops me dead in my tracks (even before I attempt it in W7)

I may be forced to consider a separate index text file (or DB records), but that may be difficult to keep in kilter.
Or alter the file name (which user does not want), and keep that fact hidden from the users (I put tags there, the user does not see it, I remove the tags before the file goes anywhere out of the folder). There is more than one form/code that does things to that folder, so that too may be difficult to maintain.

Anyone have other suggestions,
Rob
Remote Training and Programming
Top Expert 2015
Commented:
Wayne Phillips' Access utility to read file information works in XP

Accessing detailed file information provided by the Operating System
  by Wayne Phillips
http://www.everythingaccess.com/tutorials.asp?ID=Accessing-detailed-file-information-provided-by-the-Operating-System
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
If you use an application to manage categories, you've all kind of choices. A separate file (e.g. Access/Jet database) is least invasive but more complex to implement.
Alternate Data Streams contain additional content, and are directly bound to the corresponding file (they are a part of it, and in fact Office uses them too). Sad thing is I have no clue how to implement anything related in VB ...
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
adding on ...
In addition to reading file metadata, Wayne's utility also has helper functions in the code to change file property values, so Access could also be used to write and manage the tags.
Top Expert 2014

Commented:
XP might be a limiting factor.  Are they using FAT or NTFS?

Author

Commented:
We are all NTFS.
I'm the only one using XP (to develop it in my VB6 IDE)
They all are using W7 and W10 PCs, where they will be using it, if I ever get it working.
I have a W7/W10 PC that I can test in, before giving it to them.
I believe that Metadata/Attributes are not very well supported by MS in W7 and W10

Thanks all for contributing,
Rob
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
you're welcome

I agree that support is lacking -- luckily there are some who figure it out and share tools freely ~   did you try Wayne's File PropertyViewer on EverythingAccess? When you launch it, you can browse to a file and see property names and values -- that in itself is a good enough reason to pin it to my Taskbar  ... and behind the scenes, there is even more! There is a NativeCode module that only Wayne can read ... but the rest of the code is read-able --change-able, and CALL-able.

Since you are strong in VB, you have good foundation for developing in Access since it uses VBA (Visual Basic for Applications -- Access adds libraries for working with data structure). I realize the topics for this question did not include Access ... perhaps it should be a consideration ....  in addition to free tools that can benefit your needs, there are great Access experts here that are happy to guide you if you ask for help ...

Author

Commented:
Crystal,
I have downloaded Wayne's utility.
Yup it is listing the contents of the Tag and Comments properties (which i am leaning towards using).
I just manually gave the PDF file a Comment and Tag, and they both show up fine in Wayne's utility.
(The DSOfiles.dll still gives that same error, so that rules it out)
I don't see the ability to enter(write) the properties.
I notice you said " helper functions in the code to change file property values", so I reckon you are saying if I browse/understand the code, I should be able to work out how to write the desired properties ?

Thanks for assisting,
Rob
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
you'we welcome, Rob

> "change file property values"

read the comments on the download page, it is explained
Under NTFS you can use alternate data streams (ADS). Here is a module you can use:
Option Explicit
'
Private Const OF_EXIST = &H4000
Private Const OFS_MAXPATHNAME = 128
'
Private Type OFSTRUCT
    cBytes As Byte
    fFixedDisk As Byte
    nErrCode As Integer
    Reserved1 As Integer
    Reserved2 As Integer
    szPathName(OFS_MAXPATHNAME) As Byte
End Type
'
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Public Function Read_ADS(strFileName As String) As Variant
    Dim FileData As Variant
    Open strFileName For Binary Access Read As #1
        Get #1, , FileData
    Close #1
    Read_ADS = FileData
End Function

Public Sub Write_ADS(strFileName As String, FileData As Variant)
    Open strFileName For Binary Access Write As #1
        Put #1, , FileData
    Close #1
End Sub

Public Function ADS_FileExist(strFileName As String) As Boolean
    Dim OF As OFSTRUCT
    ADS_FileExist = OpenFile(strFileName, OF, OF_EXIST) = 1
End Function

Public Sub Delete_ADS(strFileName As String)
    If ADS_FileExist(strFileName) Then
        DeleteFile strFileName
    End If
End Sub

Open in new window

ADS file path looks like YourFilePathWithExtension:myData.dat You can write to ADS without influence to main file stream.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial