I am working on an app an I am populating a ListBox with the information contained in a folder like, name, date modified and size. I would like to also add the type of file, like what you get on Windows.
Microsoft Word Document
PNG Image
Is there a way to retrieve the information from the file directly?
Does that mean I have to create a case for every possible type of files available on the computer?
I tried to find a list with all possible extensions and there are a few hundreds possible… I could always create a database with the extension and associated application and search through it when I fill the listbox, but it looks like quite a bit of work.
bear in mind the “extension” of a filename does NOT necessarily indicate the contents of the file.
For example, and SQLite database could be “test.db”, “test.sqlite”, “test.mystuff”
even using the app that is desiginated to open a file by default won’t really help, as each user may have different preferences
Not only that, but you also can fall into some genius job: Ive changed the file type from avi to mp4. Now my application can open that file !.
Or, like what Ive done some times ago: Ive made an error in a batch rename and set jpg instead of gif as extension image files. Now, I check the images inside tag to decide what will be the file extension.
Does that mean I have to create a case for every possible type of files available on the computer?
I tried to find a list with all possible extensions and there are a few hundreds possible… I could always create a database with the extension and associated application and search through it when I fill the listbox, but it looks like quite a bit of work.
Are you aware of any simpler way?
[/quote]
All depends what you are after. I am sorry, but your question was about Word and png. What I posted is very simply the answer.
It addresses Word, and png. If that is the only types you want, that is all you need. You certainly don’t need to select case every file.
Now, if you want to identify ALL files, that is an entirely different proposition.
If you don’t really know which file types you want to address, it is difficult to help.
You are right, my initial question was not that clear… Sorry about that. The application I am working on will have to display all files available in a folder. I already have that working but I am trying to add a column where the file type would be also indicated. I am looking for something that is pretty much like what Windows will display.
@Richard Hille : This might help. It maps a file extension to a MIME type. It is by no means an exhaustive list, but it might help get you going.
If you want to see it in action, it’s included as part of Xojo Web Frame and it’s used in the demo to serve up static files (stylesheets, images, etc).
Public Function MIMETypeGet(Extension As String) as String
Select Case Extension
Case "ai"
Return "application/postscript"
Case "bmp"
Return "image/bmp"
Case "csv"
Return "text/plain"
Case "doc"
Return "application/msword"
Case "docx"
Return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Case "eps"
Return "application/postscript"
Case "fmp12"
Return "application/x-filemaker"
Case "fmp7"
Return "application/x-filemaker"
Case "gif"
Return "image/gif"
Case "jpeg"
Return "image/jpeg"
Case "jpg"
Return "image/jpeg"
Case "json"
Return "application/json"
Case "mer"
Return "text/plain"
Case "mov"
Return "video/quicktime"
Case "mp3"
Return "audio/mpeg"
Case "mp4"
Return "video/mp4"
Case "ogg"
Return "application/ogg"
Case "pct"
Return "image/x-pict"
Case "pdf"
Return "application/pdf"
Case "png"
Return "image/png"
Case "pps"
Return "application/vnd.ms-powerpoint"
Case "ppsx"
Return "application/vnd.openxmlformats-officedocument.presentationml.slideshow"
Case "ps"
Return "application/postscript"
Case "psd"
Return "application/psd"
Case "rtf"
Return "application/rtf"
Case "sit"
Return "application/x-sit"
Case "svg"
Return "image/svg+xml"
Case "tab"
Return "text/plain"
Case "tif"
Return "image/tif"
Case "tiff"
Return "image/tiff"
Case "txt"
Return "text/plain"
Case "xls"
Return "application/vnd.ms-excel"
Case "xlsx"
Return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Case "zip"
Return "application/x-compressed"
Case "zipx"
Return "application/x-zip-compressed"
Else
Return "binary/octet-stream"
End Select
End Function
Tims code, does not guarantee that the returned MIME type is appropriate for the CONTENTS of the file, only that it is appropriate for a file whose content matches the extension.